VBA loop bold

Z

Zeljko

I need to find ALL ocurances of word "Name:" or "Adress: A" or ... in that
*.doc and then boldit complete row where is that word.
Problem is that with this code it only bold rows where it finds first
ocurances of word "Name:" or "Adress: A" or ...
I try everything and i can't find solution. Plese help if u can.
To start macro i call procedure Replace_Bold

I have next code:

Sub DoFindBold(FindText As String)
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = FindText
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
If Selection.Find.Found Then
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.Find.Execute
Else
Selection.Find.Execute
End If
End Sub

///// and another one

Sub Replace_Bold()
Call DoFindBold("Name:")
Call DoFindBold("Adress: A")
' ... line call continues ca. 150 times ...
End Sub
 
H

Helmut Weber

Hi Zeljko,

you don't need more than this in principle:

Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "brown"
While .Execute
rDcm.Select
rDcm.Bookmarks("\Line").Range.Font.Bold = True
Wend
End With

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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