Question : VBA Word

Hi,

I want to ise VBA to insert a series of tables in a word doc for 'count' times within a loop. How would the range be set so that within the loop each table follows the rpeceding one?

For 1 to count
        Set myRange = objDoc.Range( ??? )
        objDoc.Tables.Add Range:=myRange, NumRows:=3, NumColumns:=4
next

Answer : VBA Word

You need to put a paragraph mark between the tables, or they will merge together.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Sub InsertTables(objDoc As Word.Document)
    Dim objTable As Word.Table
    Dim MyRange As Word.Range
    Dim t As Integer
    
    Const Count = 5
    
    Set MyRange = objDoc.Range
    For t = 1 To 5
        Set objTable = objDoc.Tables.Add(MyRange, 3, 4)
        Set MyRange = objTable.Range
        MyRange.Collapse wdCollapseEnd
        MyRange.Move wdCharacter, 1
        MyRange.Text = vbCr
        MyRange.Collapse wdCollapseEnd
        MyRange.Move wdCharacter, 1
    Next t
End Sub
Random Solutions  
 
programming4us programming4us