Hilight all occurrences of Arial font formatting

A

andreas

Dear Experts:

below macro is supposed to hightlight all occurrences (words/
characters) that feature the Arial font.

Somehow the macro skips whole paragraphs and does not higlight all
occurrences of Arial font formatting in my document. How come?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


Sub HighlightFontArial()
Dim rng As range

Set rng = ActiveDocument.StoryRanges(wdMainTextStory)

With rng.Find
.ClearFormatting
.Font.Name = "Arial"
.Forward = True
.Wrap = wdFindStop
End With

Do While rng.Find.Execute
rng.HighlightColorIndex = wdYellow
Loop
End Sub
 
S

Steve Yandl

Andreas,

Try this.

'---------------------------------------------------------------

Sub HighlightArialFont()

Dim rng As Range
Dim intPosition As Long

Set rng = ActiveDocument.StoryRanges(wdMainTextStory)

With rng
..Find.Font.Name = "Arial"
..Find.Forward = True
Do While .Find.Execute
.HighlightColorIndex = wdYellow
intPosition = .End
..Start = intPosition
Loop
End With

End Sub

'---------------------------------------------------------------

Steve Yandl
 
A

andreas

Andreas,

Try this.

'---------------------------------------------------------------

Sub HighlightArialFont()

Dim rng As Range
Dim intPosition As Long

Set rng = ActiveDocument.StoryRanges(wdMainTextStory)

With rng
.Find.Font.Name = "Arial"
.Find.Forward = True
Do While .Find.Execute
    .HighlightColorIndex = wdYellow
intPosition = .End
.Start = intPosition
Loop
End With

End Sub

'---------------------------------------------------------------

Steve Yandl














- Show quoted text -

Hey Steve,

thank you very much for your swift help. The macro falls into an
endless loop, BUT it is working as desired. Do you think it Is
possible for you to remove this 'endless loop'?

Regards, Andreas
 
D

Doug Robbins - Word MVP

Use:

Selection.HomeKey wdStory
Selection.Find.Font.Name = "Arial"
With Selection.Find
Do While .Execute(FindText:="", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Selection.Range.HighlightColorIndex = wdYellow
Selection.Collapse wdCollapseEnd
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Andreas,

Try this.

'---------------------------------------------------------------

Sub HighlightArialFont()

Dim rng As Range
Dim intPosition As Long

Set rng = ActiveDocument.StoryRanges(wdMainTextStory)

With rng
.Find.Font.Name = "Arial"
.Find.Forward = True
Do While .Find.Execute
.HighlightColorIndex = wdYellow
intPosition = .End
.Start = intPosition
Loop
End With

End Sub

'---------------------------------------------------------------

Steve Yandl














- Show quoted text -

Hey Steve,

thank you very much for your swift help. The macro falls into an
endless loop, BUT it is working as desired. Do you think it Is
possible for you to remove this 'endless loop'?

Regards, Andreas
 
T

Tony Jollans

You don't need a loop at all.

Options.DefaultHighlightColorIndex = wdYellow
With ActiveDocument.Content.Find
.Font.Name = "Arial"
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
End With

--
Enjoy,
Tony

www.WordArticles.com

Andreas,

Try this.

'---------------------------------------------------------------

Sub HighlightArialFont()

Dim rng As Range
Dim intPosition As Long

Set rng = ActiveDocument.StoryRanges(wdMainTextStory)

With rng
.Find.Font.Name = "Arial"
.Find.Forward = True
Do While .Find.Execute
.HighlightColorIndex = wdYellow
intPosition = .End
.Start = intPosition
Loop
End With

End Sub

'---------------------------------------------------------------

Steve Yandl














- Show quoted text -

Hey Steve,

thank you very much for your swift help. The macro falls into an
endless loop, BUT it is working as desired. Do you think it Is
possible for you to remove this 'endless loop'?

Regards, Andreas
 
A

andreas

You don't need a loop at all.

    Options.DefaultHighlightColorIndex = wdYellow
    With ActiveDocument.Content.Find
        .Font.Name = "Arial"
        .Replacement.Highlight = True
        .Execute Replace:=wdReplaceAll
    End With

--
Enjoy,
Tony

 www.WordArticles.com











Hey Steve,

thank you very much for your swift help. The macro falls into  an
endless loop, BUT it is working as desired. Do you think it Is
possible for you to remove this 'endless loop'?

Regards, Andreas- Hide quoted text -

- Show quoted text -

Hey Tony,

great this did the trick. Thank you very much for your professional
help. Regards, Andreas
 
A

andreas

Use:

Selection.HomeKey wdStory
Selection.Find.Font.Name = "Arial"
With Selection.Find
    Do While .Execute(FindText:="", Forward:=True, _
    MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
        Selection.Range.HighlightColorIndex = wdYellow
        Selection.Collapse wdCollapseEnd
    Loop
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP











Hey Steve,

thank you very much for your swift help. The macro falls into  an
endless loop, BUT it is working as desired. Do you think it Is
possible for you to remove this 'endless loop'?

Regards, Andreas- Hide quoted text -

- Show quoted text -

Dear Dough,

thank you very much for your professional help. I am afraid to say
that your code althought it does the highlighting also falls into an
endless loop. I tried Tony Jallon's macro. It is working fine.

Thank you very much for your help. Regards, Andreas
 
D

Doug Robbins - Word MVP

Not here it doesn't. After the last section of Arial text in the document
has been highlighted, the selection is moved to the beginning of the next
word.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

Use:

Selection.HomeKey wdStory
Selection.Find.Font.Name = "Arial"
With Selection.Find
Do While .Execute(FindText:="", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Selection.Range.HighlightColorIndex = wdYellow
Selection.Collapse wdCollapseEnd
Loop
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP











Hey Steve,

thank you very much for your swift help. The macro falls into an
endless loop, BUT it is working as desired. Do you think it Is
possible for you to remove this 'endless loop'?

Regards, Andreas- Hide quoted text -

- Show quoted text -

Dear Dough,

thank you very much for your professional help. I am afraid to say
that your code althought it does the highlighting also falls into an
endless loop. I tried Tony Jallon's macro. It is working fine.

Thank you very much for your help. Regards, Andreas
 

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