PDA

View Full Version : Solved: Tables In Word Query



petedw
07-04-2005, 01:03 AM
Hey guys,

A bit of advice if you may.... When telling VBA to delete certain tables, i have to tell it the number of the table that i wish to delete.
This is causing me quite a few problems because this number is always different.
For example, i may tell vba to delete table(6) but occasionally a table before this doesnt exist and so it becomes table(5).
Is there a way of naming your tables so that you can refer to them easily??: pray2:

Many Thanks

Pete

MOS MASTER
07-04-2005, 08:24 AM
Hi Pete, :yes

Depends on what you find easy?

All possibillities are listed in this simular topic:
http://www.vbaexpress.com/forum/showthread.php?t=3512

Enjoy! :whistle:

petedw
07-04-2005, 08:27 AM
Thanks Joost, that'll do me:beerchug:

fumei
07-04-2005, 08:30 AM
No, unfortunately there is not really.

However, that being said, there is a way to get around it. It depends on your requirements.

As you have discovered Tables(6).Delete will delete the sixth table (regardless of whether it is the correct one) OR give an error because there is only five now (as an example).

The easiest solution is to bookmark your tables. Select the whole table, give it a bookmark. Now if you want to delete it (or select it, or whatever), you can reference directly, as a bookmark. Such as:

ActiveDocument.Bookmarks("Table6").Delete

Just remember that in the above example, "Table6" is a name. If you selected the first table and named its bookmark as Table6....then that would be its name.

So say you have a table of, I don't know, client names and addresses. Make it a bookmark named ClientInfo. You can now reference it, action it, as a bookmark.

MOS MASTER
07-04-2005, 08:32 AM
Glad to here...Ps...take on Gerry's advice! :beerchug:

petedw
07-04-2005, 08:42 AM
Make it a bookmark, of course!! I can't believe i didnt think of that:doh:

Thanks Gerry