A
aklein
Hi.
I am trying to insert multiple tables in my Word document. I am
actually adding them in reverse order (ie: add one table, then add
another one BEFORE it ... and another one BEFORE that one). (The
reason I am doing this is somewhat hard to explain.... but will go
into it if someone needs to know!)
The problem is that each time I add a new table, it seems to nest
itself in the first cell of the table I had previously created.
I am trying to get to the point BEFORE the table so I can add a table
without it being nested.
The relevant code:
(The missing code opens Word - as this is called from Access - based
on a template that has the bookmark "GroupList" and sets the
ActiveDocument).
--------------------------
Dim objWord as Word.Application
Dim oRng as Word.Range
Set oRng = objWord.ActiveDocument.Bookmarks("Grouplist").Range
oRng.Select
'BUILD THE TABLE WITH BORDERS ETC.
'THIS CODE IS IN A LOOP THAT READS FROM A RECORDSET
While not rst.EOF
Set objTable =
objWord.ActiveDocument.Tables.Add(Range:=oRng, NumRows:=10,
NumColumns:=3)
objTable.Borders.OutsideLineStyle = wdLineStyleSingle
objTable.Borders.OutsideLineWidth = wdLineWidth025pt
objTable.Borders.InsideLineStyle = wdLineStyleSingle
objTable.PreferredWidthType = wdPreferredWidthPercent
objTable.PreferredWidth = 100
'USED FOR SOME PURPOSE LATER ON
tablecount = tablecount + 1
With objTable
myRowCount = 1
'TABLE IS POPULATED BY THE rst RECORDSET'S DATA USING
'.Cell(myRowCount,myColumn).Range.Text
'AS THIS PIECE IS WORKING... I SNIPPED IT OUT
'ONCE THE TABLE HAS ALL THE DATA... I DO THE FOLLOWING
'try to get before the table !
oRng.Collapse (wdCollapseStart)
oRng.InsertParagraph
oRng.Move wdCharacter, -1
oRng.InsertAfter ""
'get before that
oRng.Collapse (wdCollapseStart)
'add the bookmard back in to use again?
objWord.ActiveDocument.Bookmarks.Add ("GroupList")
oRng =
objWord.ActiveDocument.Bookmarks("GroupList").Range
oRng.Select
oRng.Collapse (wdCollapseEnd)
End With
'are done with this table
Set objTable = Nothing
'move on to the next record and add another table...
rst.movenext
wend
-----------------------------------------------
I am sure the secret has something to do with the Range... but I have
been unsuccessful with all my attempts. I am new to Word VBA (though
not Access).
Any help would be appreciated!
Aliza
I am trying to insert multiple tables in my Word document. I am
actually adding them in reverse order (ie: add one table, then add
another one BEFORE it ... and another one BEFORE that one). (The
reason I am doing this is somewhat hard to explain.... but will go
into it if someone needs to know!)
The problem is that each time I add a new table, it seems to nest
itself in the first cell of the table I had previously created.
I am trying to get to the point BEFORE the table so I can add a table
without it being nested.
The relevant code:
(The missing code opens Word - as this is called from Access - based
on a template that has the bookmark "GroupList" and sets the
ActiveDocument).
--------------------------
Dim objWord as Word.Application
Dim oRng as Word.Range
Set oRng = objWord.ActiveDocument.Bookmarks("Grouplist").Range
oRng.Select
'BUILD THE TABLE WITH BORDERS ETC.
'THIS CODE IS IN A LOOP THAT READS FROM A RECORDSET
While not rst.EOF
Set objTable =
objWord.ActiveDocument.Tables.Add(Range:=oRng, NumRows:=10,
NumColumns:=3)
objTable.Borders.OutsideLineStyle = wdLineStyleSingle
objTable.Borders.OutsideLineWidth = wdLineWidth025pt
objTable.Borders.InsideLineStyle = wdLineStyleSingle
objTable.PreferredWidthType = wdPreferredWidthPercent
objTable.PreferredWidth = 100
'USED FOR SOME PURPOSE LATER ON
tablecount = tablecount + 1
With objTable
myRowCount = 1
'TABLE IS POPULATED BY THE rst RECORDSET'S DATA USING
'.Cell(myRowCount,myColumn).Range.Text
'AS THIS PIECE IS WORKING... I SNIPPED IT OUT
'ONCE THE TABLE HAS ALL THE DATA... I DO THE FOLLOWING
'try to get before the table !
oRng.Collapse (wdCollapseStart)
oRng.InsertParagraph
oRng.Move wdCharacter, -1
oRng.InsertAfter ""
'get before that
oRng.Collapse (wdCollapseStart)
'add the bookmard back in to use again?
objWord.ActiveDocument.Bookmarks.Add ("GroupList")
oRng =
objWord.ActiveDocument.Bookmarks("GroupList").Range
oRng.Select
oRng.Collapse (wdCollapseEnd)
End With
'are done with this table
Set objTable = Nothing
'move on to the next record and add another table...
rst.movenext
wend
-----------------------------------------------
I am sure the secret has something to do with the Range... but I have
been unsuccessful with all my attempts. I am new to Word VBA (though
not Access).
Any help would be appreciated!
Aliza