Tables

G

Geoff Edwards

Using Word 97:

I am creating tables "on the fly" from code as, when and where
required thus:

Set myTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
NumRows:=NumberOfRows, NumColumns:=3)

Is there any method whereby, after the table is created, I can give it
a name so that in future I can address it by name rather than by
number given that the number might change as new tables are inserted
between others?

Or aren't they renumbered? If not, how do I get the number of the
table I am currently in?

Or would this work (eg):

Set myDirectionsTable=ActiveDocument.Tables.Add _
(Range:=Selection.Range, _
NumRows:=NumberOfRows, NumColumns:=3)

And later:

Set myWarningsTable=ActiveDocument.Tables.Add _
(Range:=Selection.Range, _
NumRows:=NumberOfRows, NumColumns:=3)

and then use:

With myWarningsTable

as opposed to what I was trying to do ie:

With ActiveDocument.Tables("DirectionsTable")


Geoff Edwards
Leeds, UK

e-mail: (e-mail address removed)
(replace the stopspambot bit with some
version of my name)
 
J

Jonathan West

Geoff Edwards said:
Using Word 97:

I am creating tables "on the fly" from code as, when and where
required thus:

Set myTable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
NumRows:=NumberOfRows, NumColumns:=3)

Is there any method whereby, after the table is created, I can give it
a name so that in future I can address it by name rather than by
number given that the number might change as new tables are inserted
between others?

You can mark the range of the table with a bookmark. But if you only need to
be able to go back to the table at other times during the running of your
macro, the myTable object variable will continue to refer to the correct
table even if other tables are inserted earlier in the document, so long as
you don't assign myTable to some other table.
Or aren't they renumbered? If not, how do I get the number of the
table I am currently in?

Thet are renumbered when you insert a new table. See this article to find
out which table you are in at the moment

Determine the index number of the current paragraph, table, section ...
http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm

Or would this work (eg):

Set myDirectionsTable=ActiveDocument.Tables.Add _
(Range:=Selection.Range, _
NumRows:=NumberOfRows, NumColumns:=3)

And later:

Set myWarningsTable=ActiveDocument.Tables.Add _
(Range:=Selection.Range, _
NumRows:=NumberOfRows, NumColumns:=3)

and then use:

With myWarningsTable

Yes, that will work for as long as the object variables remain in scope.
 
G

Geoff Edwards

Many thanks

Geoff






You can mark the range of the table with a bookmark. But if you only need to
be able to go back to the table at other times during the running of your
macro, the myTable object variable will continue to refer to the correct
table even if other tables are inserted earlier in the document, so long as
you don't assign myTable to some other table.


Thet are renumbered when you insert a new table. See this article to find
out which table you are in at the moment

Determine the index number of the current paragraph, table, section ...
http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm



Yes, that will work for as long as the object variables remain in scope.

Geoff Edwards
Leeds, UK

e-mail: (e-mail address removed)
(replace the stopspambot bit with some
version of my name)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top