Results 1 to 1 of 1
2001-03-15, 23:06 #1
- Join Date
- Feb 2001
- Yilgarn region of Toronto, Ontario
- Thanked 0 Times in 0 Posts
Code: Function lngGetTableIndex() As Long
Word97SR2: How do I determine which table of the collection of tables I am in?
I know that I am in a table with:
I know that I have a collection of tables from:
I know that I could GoTo the Next table with:
"Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, Count:=1, Name:="" "
I want to avoid the Selection thing if at all possible.
I want to know if there IS another table towards the end of the document. I figure that if I know which one this is (for eample, If the current table is ActiveDocument.Tables(5)) then I could test for the existence of Table(6).
(Once I can identify my two tables I can extract the data that lies between them and get to work).
I could loop through ActiveDocument.Tables comparing the Range values with the range of my current table, but that seems messy. I've looked at properties like Parent and Creator, but they aren't much use.
I've look at Selection.Information but that doesn't provide what I need.
In the meantime I'm going to write a FUNCTION procedure, of course, called
which function will loop through the tables colelction comparing ranges.
But there has to be a better way.
<pre>Public Function lngGetTableIndex() As Long
' Procedure : lngGetTableIndex
' Description: Return the index of the current table in the ActiveDocukment.Tables collection.
' By: Chris Greaves Inc.
' Inputs: None
' Returns: LONG index. 0 if not in table.
' Assumes: None.
' Side Effects: None.
' Tested: By the calls below.
lngGetTableIndex = 0 ' default result is "Not An Index"
If Selection.Information(wdWithInTable) Then
Dim lngStart As Long ' The current table start position
lngStart = Selection.Tables(1).Range.Start
Dim lngTable As Integer
For lngTable = 1 To ActiveDocument.Tables.Count
If ActiveDocument.Tables(lngTable).Range.Start = lngStart Then
lngGetTableIndex = lngTable ' Return this index