Opera362
asked on
How to obtain a table ID (Word automation)
Hi all,
I have a bookmark inside a table in a Word document. I need to access directly from VBA to the cells of that table. I would like to do with:
ActiveDocument.Tables(tabl eID).Rows( rownumber) .Cells(cel lnumber).e tc.
But, how can I know the "TableID" which a bookmark is in?
Actually, I've found to modify cells more or less with:
mywordobj.ActiveDocument.b ookmarks(" bkmID").Se lect
mywordobj.Selection.Select Row
mywordobj.Selection.Cells( 1).Range.T ext = "<some text>"
But I don't want to do that way, because when the cell is updated, I lose the selection and I have to start again selecting the row, etc.
If you have any suggestions to access table cells in a different manner, they will be welcome :-)
Many thanks
I have a bookmark inside a table in a Word document. I need to access directly from VBA to the cells of that table. I would like to do with:
ActiveDocument.Tables(tabl
But, how can I know the "TableID" which a bookmark is in?
Actually, I've found to modify cells more or less with:
mywordobj.ActiveDocument.b
mywordobj.Selection.Select
mywordobj.Selection.Cells(
But I don't want to do that way, because when the cell is updated, I lose the selection and I have to start again selecting the row, etc.
If you have any suggestions to access table cells in a different manner, they will be welcome :-)
Many thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I gave you the points gilbar for the time you spent writing that code, etc. Although it wasn't the solution I was looking for, it gave me an advice. Thanks for your time!
:-)
:-)
Thank YOU opera362, your plan certainly does the trick
ASKER
I've finally found how to obtain some Table index, or some other object that has a Range property:
In brief, the trick is to, while staying at a make a Range from the beginning of the document, to the actual range.end. Then do a Table.Count and you now have the table index nomber in the integer it returns ;-) I think it's a smart solution!!!
Sample code:
Dim itable As Integer
Dim myTable As table
' Goto bookmark, and select it
myWordObj.ActiveDocument.b
' Get index of table bookmark is inside of (GOOD!!!)
itable = myWordObj.ActiveDocument.R
' Now capture that table
Set myTable = myWordObj.ActiveDocument.T
' And then, it's easy to do things like this
myTable.Cell(nrow, ncol).Range.Text = "At last!!"
You can view full explanation at:
"Determine the index number of the current paragraph, table, section ..."
http://www.mvps.org/word/FAQs/MacrosVBA/GetIndexNoOfPara.htm