Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 01-17-2011, 12:37 PM
smed smed is offline Windows XP Office 2007
Novice
 
Join Date: Jan 2011
Posts: 3
smed is on a distinguished road
Question VBA find or name a Table

I would like to know how to find or name a table using VBA, either method will solve my problem. By naming a table I mean that I can access a table called "Table1" by something like this:

celltext = ActiveDocument.Tables("Table1").Cell(1, 1).Range.Text

I can't simply use the index of the table because it may change depending if more tables are added before the one I want to access.

Thanks.
Reply With Quote
  #2  
Old 01-17-2011, 01:18 PM
macropod's Avatar
macropod macropod is online now Windows 7 32bit Office 2000
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 10,528
macropod is a jewel in the roughmacropod is a jewel in the roughmacropod is a jewel in the roughmacropod is a jewel in the rough
Default

Hi smed,

If you bookmark the table, you can find the first table in the bookmarked range. For example:
Code:
celltext = ActiveDocument.Bookmarks("Table1").Range.Tables(1).Cell(1, 1).Range.Text
Do note, though, that specifying 'Cell(1, 1).Range.Text' pick up the end-of-cell marker. To get just the cell's text range, use something like:
Code:
Dim CelRng As Range
Set CelRng = ActiveDocument.Bookmarks("Table1").Range.Tables(1).Cell(1, 1).Range
CelRng.End = CelRng.End - 1
celltext = CelRng.Text
To bookmark a table, you don't need to select the whole table. You can simply bookmark any of the end-of-row markers.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]

Last edited by macropod; 01-17-2011 at 06:25 PM.
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
find and replace anil3b2 Word 0 08-03-2010 11:30 PM
can Find/Replace NOT find something? Bobosmite Word 6 05-27-2010 08:09 PM
Pasting table in Photoshop cutting off table azdolfan Word Tables 0 05-16-2010 01:52 PM
Find Hyperlinks jimbassett Excel 2 02-08-2010 07:08 AM
Find and add new Shapes bonani PowerPoint 1 11-26-2009 05:21 PM


All times are GMT -8. The time now is 08:39 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft