
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.