Find text and select the table below the text

  • Thread starter Beginner in vba
  • Start date
B

Beginner in vba

I have written a code to search for a text, such as "List Table". I want to
select the table right below the text "List Table". But i cant seems to do
that. I want to macro to select the table below the text and copy the 1st row
data into an array. I have problem in selecting the table. Anyone can help?
Thanks a lot.
 
H

Helmut Weber

Like this:

Sub test1234()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "ferrites"
If .Execute Then
rDcm.End = ActiveDocument.Range.End
If rDcm.Tables.Count > 0 Then
rDcm.Tables(1).Select
End If
End If
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

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