> Hello everyone!
>
[quoted text clipped - 16 lines]
> objTable.Cell(3, 3).Select
> objTable.Tables.Add Selection.Range, 2, 2
Normally, you should always use objects, declare them and set them. This is
even more important when automating Word from anohter app.
Also, never use the Selection object, unless there is no other way (e.g.
when inserting a shape in a header...). In your case, you do not need the
Selection object.
Finally, never use ActiveDocument when automating Word.
Here is sample code that does what your code does, but taking into
consideration the points I mention above (I have to twist things a bit since
I do ot have a document with a "Table" bookmark in it...):
Option Explicit
Sub test()
Dim docMain As Document
Dim rngTable As Range
Dim tblMain As Table
Dim tblNested As Table
Dim intOps As Long
Const strTbleBookMark As String = "Table"
intOps = 5
Set docMain = Application.Documents.Add
Set rngTable = docMain.Paragraphs(1).Range
With rngTable
.InsertParagraphAfter
.InsertParagraphAfter
.InsertParagraphAfter
.MoveEnd wdCharacter, -2
.Collapse wdCollapseEnd
.Bookmarks.Add strTbleBookMark, rngTable
End With
Set rngTable = docMain.Bookmarks(strTbleBookMark).Range
Set tblMain = docMain.Tables.Add(rngTable, intOps + 1, 3)
Set rngTable = tblMain.Cell(3, 3).Range
rngTable.Collapse wdCollapseStart
Set tblNested = docMain.Tables.Add(rngTable, 2, 2)
End Sub
With this code I can refer to both tables as I wish because I declared
separate objects for them.
I could have declared two different Range object, and would do so if I
needed to refer to each range again later in the code. Here, each range is
disposable once it has been used, so I just reset the same range object again
and again...
Freaker - 09 May 2008 21:09 GMT
Jean-Guy-Marcil
Thank you so much for what you have written. The terms I have seen you use
(particularly the .Collapse expression) do not come up in Access
documentation so I have not seen them before.
I will need to change it slightly to work within the Access framework but
what you have written is so clear that it will be easy to convert it, then I
can step through it which will help me emensly. I will try this tomorrow and
I will let you know what the results are
Thank you
Craig
Jean-Guy Marcil - 13 May 2008 14:00 GMT
> Jean-Guy-Marcil
> Thank you so much for what you have written. The terms I have seen you use
> (particularly the .Collapse expression) do not come up in Access
> documentation so I have not seen them before.
Of course you haven't seen it in Access, it is part of the Word Object
Model. If you set a reference to the Word Object model from within the Acces
VBA editor, you should have acces to the Word VBA help files.
> I will need to change it slightly to work within the Access framework but
> what you have written is so clear that it will be easy to convert it, then I
> can step through it which will help me emensly. I will try this tomorrow and
> I will let you know what the results are