Getting Table Number of Word Table 
Author Message
 Getting Table Number of Word Table

Hi,

How can I retrieve the table number of a table in a word doc.  For example:
I have a word doc that has about six tables in it or more...I search for a
word...find the word...now I would like to know what table number the word
was found in.  I've created code to only search tables in the word doc but
can not figure out how to retrieve the table number of a word table.  Any
ideas anyone?  Thanks



Sat, 07 Dec 2002 03:00:00 GMT  
 Getting Table Number of Word Table
Dana

Try this. Add the function and macro below to your VBA module. In the
macro TestTableNumber substitute the word you are searching for with
"Your Word". The function will find the first occurance of the word and
give the table number.

Function TableNumber(MyWord As String) As Integer
    Dim Doc As Word.Document
    Dim MyRange As Word.Range
    Set Doc = ActiveDocument
    Set MyRange = Doc.Range(Start:=0, End:=Doc.Content.End)
    Do While MyRange.Find.Execute(Findtext:=MyWord, MatchCase:=True,
Forward:=True) = True
        If MyRange.Information(wdWithInTable) Then
        TableNumber = Doc.Range(Start:=0, End:=MyRange.End).Tables.Count
            Exit Function
        End If
    Loop
End Function

Sub TestTableNumber()
    MsgBox TableNumber("Your Word")
End Sub



Quote:
> Hi,

> How can I retrieve the table number of a table in a word doc.  For
example:
> I have a word doc that has about six tables in it or more...I search
for a
> word...find the word...now I would like to know what table number the
word
> was found in.  I've created code to only search tables in the word doc
but
> can not figure out how to retrieve the table number of a word table.
Any
> ideas anyone?  Thanks

Sent via Deja.com http://www.deja.com/
Before you buy.


Fri, 13 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting Text from Table Causes Problems with the Row Number

2. Getting/Setting Record Number in VB4 Tables?

3. Pass number from Word table to VBA variable

4. Auto Numbering in a Word Table

5. Getting the total of a Table column, in MS Word using VBA

6. macro for converting EMF tables in Word to normal cellular Tables

7. Import/Export to WORD XP Table to/from SQL Table

8. Word Spreadsheet Functionality in Word Table

9. getting number of pages in word

10. Getting page numbers from Word 2000

11. getting number of pages in word

12. line numbers in order detail table

 

 
Powered by phpBB® Forum Software