I use a simple trick told me by Cetin Basoz:
LOCAL llContinue, loTable,lcBkMarkToFind
#include wdconst.h
lcBkMarkToFind = "Table5"
WITH oWord.activedocument
IF .Bookmarks.EXISTS(lcBkMarkToFind)
.Bookmarks(lcBkMarkToFind).SELECT
WITH .APPLICATION.SELECTION
.Collapse(wdCollapseEnd)
IF .INFORMATION(wdWithInTable)
llContinue = .T.
ENDIF
ENDWITH
IF llContinue
loTable = .APPLICATION.SELECTION.TABLES(1)
ENDIF
ELSE
ENDIF
ENDWITH
I just stripped out and adjusted some code from my app so I hope it is clear what I am doing here.
>Della,
>Assuming that I have a table (nTable) with a bookmark in Cell[1,1], you say that the oBookmarkRange variable is equal to oWord.Tables[nTable].Cell[1,1].Range. Is there a simple way of going from there to a variable oWord.Tables[nTable]? Assuming (as earlier in the thread) that you don't know the table #? I have an app. with a lot of Word automation, including multiple tables, and every so often the client will add a table into the original template, which upsets the table numbering. Since I'm doing some fairly elaborate formatting in the tables I'd really like to get the oWord.Tables(nTable) object in a simple manner.
>
>TIA
>Barbara
>
>
>>I saw your other reply, and Garrett's solution is definitely the faster and cleaner solution! (I was under the impression that you'd be adding to an existing table.)
>>
>>You may run into the similar situations, so I'll explain my answer a bit better. I'm assuming that your bookmark is somewhere in a table's cell, say oWord.Tables[1].Cell[1,1]. When you ask for the Range of the bookmark and set a variable to oBookmarkRange, you get a variable equal to oWord.Tables[1].Cell[1,1].Range. So if you've ensured oBookmarkRange is within a table with oBookmarkRange.Information(wdWithinTable), you know you've got a cell, and you can act on it just like referencing any other cell, and insert text, format, whatever needs to be done, as in oBookMark.InsertAfter("Hello World").
>>
>>Hope this helps!
>>
>> - della
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro
"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison