> I’m writing a macro where I need to create a series of tables in a new MS
> Word (2000) document and import text into each table. Each table needs a
[quoted text clipped - 16 lines]
> second table inside the first table. I figure I’m not understanding how
> “Selection” works. Any help here would be greatly appreciated.
This adds three tables at the current insertion point, each followed by four
empty paragraphs (¶):
Sub Test()
Dim oTbl As Table
Dim i As Long
Dim rgeTble As Range
Dim objNewDoc As Document
Set objNewDoc = ActiveDocument
Set rgeTble = Selection.Range
i = 1
For i = 1 To 3
Set oTbl = objNewDoc.Tables.Add(Range:=rgeTble, numrows:=3, numcolumns:=1)
With oTbl
.Range.Borders.Enable = False
.Cell(1, 1).Range.Text = "Add text here."
With .Cell(2, 1).Range
.Style = "Diagram"
.Text = "Add a chess diagram font text here."
End With
.Cell(3, 1).Range.Text = "Add text here."
Set rgeTble = .Range
With rgeTble
.MoveEnd wdCharacter, 1
.InsertAfter Chr(13) & Chr(13) & Chr(13) & Chr(13)
.Collapse wdCollapseEnd
End With
End With
Next
End Sub
You may want to add some checking in the code to make sure that the current
insertion point is not inside a table or is a selected object...
StevenM - 25 Mar 2008 21:54 GMT
To: Jean-Guy Marcil,
Thank you, that is just what I needed! Thank you very much.
Steven Craig Miller