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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select a specific table using VBA in Word 97 1

Status
Not open for further replies.

mmtraining

IS-IT--Management
Mar 18, 2002
104
DE
I am setting up a document template and have got a nice little bit of VBA that checks a table for double entries.

My problem:

I need to check a specific table, not the others. Users can make as many tables before and after this one, so I can't use a fixed index. Can I name a table or use a bookmark to get to it or is there an object active table? Please help, as that would make my template perfect.

Thanx a lot in advance

Carol
Berlin, Germany
 
'Create table at current selection
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=2
'Create bookmark at table location
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Tabl"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With



'Goto the table
Selection.GoTo What:=wdGoToBookmark, Name:="Tabl"
 
Alternatively if you know the contents of a specific cell in the table...

For Each oTable In ActiveDocument.Tables
For Each oCell In oTable.Rows(1).Cells
Set myRange = oCell.Range
myRange.MoveEnd Unit:=wdCharacter, Count:=-1
MsgBox myRange.Text
If (myRange.Text = "TEST") Then
oTable.Select
End If
Next oCell
Next oTable
 
Awesome scripting.....

This will return if you're in a table or not.....

If appWord.Selection.Information(wdWithInTable) Then Thank you,
Dave Rattigan
 
Thanks a lot so far, both of you, but......

It's not quite what I am after. The table already exists, so I don't need to create it, the problem I have got is that I need to know which table the cursor is in (I just sorted the contents of the table), so I can get rid of double entries just in the active table.

Is there a keyword like activetable? Heeeeeeeeeeelllllllllllppppp

Carol
Berlin, Germany
 
try something like this:

Code:
Dim ActiveTBL As Table

Set ActiveTBL = Selection.Tables(1)

' ActiveTBL.Cell(1, 1).Range.Text = "updated"

Set ActiveTBL = Nothing

but what if the selection contains more than one table?
If Selection.Tables.count > 1 then ?

 
Ratman, Olaf Bogus and JustinEzequiel, all three of you have contributed to the solution of my problem. Thank you all very much.

I am now able to sort the table the cursor was in, removing the double entries that are there. Wonderful.

All the best from tornado-struck Berlin (10.07.02)

Carol :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top