Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tables in word

Status
Not open for further replies.

Killa

Programmer
Oct 19, 2001
56
US
Is there an easy way of identifying tables?
can tables be named ?

i want to create and edit a set number of tables using vba

I have a button on the document for each table which opens the relevant form but i need to the data from table into the form and visa versa, this maybe done several times before the document is complete

I hope i explained this ok any help would be much appreciated
 
Killa

I used the Object Browser to help on this one.
Code:
ThisDocument.Tables(1).ID = "Table 1"


Skip,

[glasses] [red]Be advised:[/red] Researchers have found another Descartes trueism, "Cogito ergo spud."
"I think; therefore, I YAM!
[tongue]
 
There is a name property for tables, but it applies to mailmerges. There is a workaround.

Code:
Sub MakeTableBookmarks
' // goes through every table and 
' // makes the ENTIRE table a bookmark range
' // this could be adjusted to just a locator
Dim var
Dim i As Integer
i = 1
Selection.HomeKey unit:=wdStory, Extend:=wdMove
For var = 1 To ActiveDocument.Tables.Count
    Selection.GoTo what:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:=""
' remove this line if just want locator
    Selection.Tables(1).Select 
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="table" & i
    End With
    i = i + 1
Next
End Sub


Private Sub CommandButton1_Click()
' // this is ActiveX button that simply selects a "named"
' // table.  This could easily be a drop down that selects
' // a table.  Note this is uses the full table range from
' // above.  In other words it selecys the entire table
Selection.GoTo what:=wdGoToBookmark, Name:="table3"
End Sub

Gerry
 
There is a name property for tables, but it applies to mailmerges. There is a workaround.

Code:
Sub MakeTableBookmarks
' // goes through every table and 
' // makes the ENTIRE table a bookmark range
' // this could be adjusted to just a locator
Dim var
Dim i As Integer
i = 1
Selection.HomeKey unit:=wdStory, Extend:=wdMove
For var = 1 To ActiveDocument.Tables.Count
    Selection.GoTo what:=wdGoToTable, _
       Which:=wdGoToNext, Count:=1, Name:=""
' remove following line if just want locator
    Selection.Tables(1).Select 
    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:="table" & i
    End With
    i = i + 1
Next
End Sub


Private Sub CommandButton1_Click()
' // this is ActiveX button that simply 
' // selects a "named" table.  This could 
' // easily be a drop down that selects a
' // table.  Note this is uses the full table 
' // range from above.  In other words it 
' // selects the entire table

Selection.GoTo what:=wdGoToBookmark, Name:="table3"
End Sub

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top