Find text and select entire line this text is in

K

Kim

I need to search for specific text in a line of text and highlight the
entire line. In my example below, I need to search for "AA" throughout
my document and once it's found select the enter line it's found on
and change to Bold, paragraph after space to 5 pt.

AA This information is good...

and
AA Not working...

I tried a Wildcard search of "AA(*)" and "AA(?)" but it doesn't
highlight everything in that row (line of text). Can I create a
wildcard search to do this, or is a macro in VBA needed?

Thanks for your help!
Kim
 
H

Helmut Weber

Hi Kim,

you need a macro.

Something along these lines:

Sub Tests()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "AA"
.MatchCase = True
While .Execute
rDcm.Select
selection.Bookmarks("\line").Select
selection.Range.HighlightColorIndex = wdYellow
Wend
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
K

Kim

Hi Kim,

you need a macro.

Something along these lines:

Sub Tests()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
   .Text = "AA"
   .MatchCase = True
   While .Execute
      rDcm.Select
      selection.Bookmarks("\line").Select
      selection.Range.HighlightColorIndex = wdYellow
   Wend
End With
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

This is what I have so far:

Sub Tests()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "AA"
.MatchCase = True

While .Execute
rDcm.Select
Selection.Font.Bold = True
Selection.ParagraphFormat.SpaceAfter = 5.5
Selection.Range.ParagraphFormat.SpaceAfter = 5.5
Wend
End With
End Sub

I also need the macro to Find "AA", and once found extend right to
highlight the whole line of text that AA is in. Where and how do I add
the line of text for the selection to highlight the AA, then Move Down
right (extend)?
 
G

Graham Mayor

You missed out the line of Helmut's code that selected the line AA is in
(indicated below)

Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "AA"
.MatchCase = True
While .Execute
rDcm.Select
'****************
Selection.Bookmarks("\line").Select
'****************
With Selection.Range
.Font.Bold = True
.Paragraphs.SpaceAfter = 5.5
End With
Wend
End With
 

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