Find text in table and select table

B

Beginner in vba

I need to find a table (in a document that have alot of table) in which one
of the column has "name". If the table has the word "name" then it will
calculate the number of row and column of the table. I still cant seems to
code it. Thanks for the help.
 
H

Helmut Weber

Hi,

like this, unless "name" appears a million times
outside of tables. In that case it would be better,
to restrict the search to the tables only.

Sub test5867()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "name"
.MatchCase = True
.MatchWholeWord = True
While .Execute
If rDcm.Information(wdWithInTable) Then
rDcm.Select
Exit Sub
End If
Wend
End With
ResetSearch
End Sub


Public Sub ResetSearch()

With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With

End Sub

And please let us know, whether this was helpful.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top