Thread: [Solved] names of tables
View Single Post
 
Old 11-14-2011, 04:19 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi hklein,

To add a title programmatically, you could use code like:
Code:
Sub Demo1()
ActiveDocument.Tables(1).Title = "MyTableTitle"
End Sub
However, if you know which table to add the title to programmatically without selecting it, you probably don't need to give it a title.

Alternatively, if you want to add a title to a selected table, you can do that through the user interface, or with code like:
Code:
Sub Demo2()
If Selection.Information(wdWithInTable) = False Then Exit Sub
Selection.Tables(1).Title = "MyTableTitle"
End Sub
Ultimately, though you'll want to do something programmatically with the titled table, for which you'll need more sophisticated code, like:
Code:
Sub Demo3()
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
  If oTbl.Title = "MyTableTitle" Then
    'Do something with the table
    Exit For
  End If
Next
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote