Creating Tables


Tables.Add

Dim objTable As Word.Table 
objTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
                                     NumRows:=3, _
                                     NumColumns:=4, _
                                     DefaultTableBehavior:=wdDefaultTableBehavior.wdWord8TableBehavior, _
                                     AutoFitBehavior:=wdAutoFitBehavior.wdAutoFitWindow)

objTable.PreferredWidthType = wdPreferredWidthType.wdPreferredWidthPoints 
objTable.PreferredWidth = 50

objTable.Rows.VerticalPosition = 0 (single value)
objTable.Rows.Alignment = wdRowAlignment.wdAlignRowLeft
objTable.Rows.HorizontalPosition = 0 (single value)
objTable.Rows.HeightRule = wdRowHeightRule.wdRowHeightAuto

objTable.Rows.RelativeHorizontalPosition = wdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage
objTable.Rows.RelativeVerticalPosition = wdRelativeVerticalPosition.wdRelativeVerticalPositionMargin


What is the difference between ??

objTable.Style = objstyle 
objTable.Range.Style = objstyle


Sub Testing() 
Dim objTable As Word.Table
 
   Set objTable = Application.ActiveDocument.Tables.Add(Range:=Application.Selection.Range, NumRows:=1, NumColumns:=1)
   
   Debug.Print objTable.PreferredWidthType
 
End Sub
 
Public Sub TestingDis_Insert()
Dim objRange As Word.Range
Dim iNoOfSections As Integer
Dim objTable As Word.Table
Dim sngTableWidthPoints As Single
 
   Application.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = 0
 
'get a range that represents the whole document
   Set objRange = Application.ActiveDocument.Range
'move to the end of the active document
   objRange.Collapse (Word.WdCollapseDirection.wdCollapseEnd)
'insert a section break at the end of the document
   objRange.InsertBreak (Word.WdBreakType.wdSectionBreakNextPage)
 
'get the total number of sections now in the document
   iNoOfSections = Application.ActiveDocument.Sections.Count
 
'unlink header and footer from the previous section
   With Application.ActiveDocument.Sections(iNoOfSections).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary)
      .LinkToPrevious = False
      .Range.Delete
   End With
   With Application.ActiveDocument.Sections(iNoOfSections).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary)
      .LinkToPrevious = False
      .Range.Delete
   End With
 
'adjust the bottom margin of this section
   With Application.ActiveDocument.Sections(iNoOfSections)
      .PageSetup.BottomMargin = Application.CentimetersToPoints(1.52)
   End With
 
'get a range that represents the end of the document
   Set objRange = Application.ActiveDocument.Range
   objRange.Collapse (Word.WdCollapseDirection.wdCollapseEnd)
   
' add a table with 1 column and 3 rows
   Set objTable = Application.ActiveDocument.Tables.Add(Range:=objRange, NumRows:=3, NumColumns:=1)
 
   sngTableWidthPoints = Application.ActiveDocument.PageSetup.PageWidth - _
                         (Application.ActiveDocument.PageSetup.LeftMargin + _
                          Application.ActiveDocument.PageSetup.RightMargin) + 8
 
   With objTable
      .PreferredWidthType = wdPreferredWidthPoints
      .PreferredWidth = sngTableWidthPoints
' With .Rows
' .VerticalPosition = Word.WdTablePosition.wdTableBottom
' .RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin
' End With
      With .Range.Font
         .Name = "Expert Sans Regular"
         .Size = 8
      End With
   End With
 
'get a range that represents the end of the document
   Set objRange = Application.ActiveDocument.Range
   objRange.Collapse (Word.WdCollapseDirection.wdCollapseEnd)
  
'selecting the line
   objRange.Expand (WdUnits.wdParagraph)
   objRange.Font.Name = "Expert Sans Regular"
   objRange.Font.Size = 8
   objRange.InsertParagraphAfter
   
   objRange.Select
   
'get a range that represents the end of the document
   Set objRange = Application.ActiveDocument.Range
   objRange.Collapse (Word.WdCollapseDirection.wdCollapseEnd)
 
'add a table with 1 column and 1 row
   Set objTable = Application.ActiveDocument.Tables.Add(Range:=objRange, NumRows:=1, NumColumns:=1)
 
   With objTable
      .PreferredWidthType = wdPreferredWidthPoints
      .PreferredWidth = sngTableWidthPoints 'use the same width we calculated above
      With .Range.Font
         .Name = "Expert Sans Regular"
         .Size = 8
      End With
   End With
 

End Sub


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext