Highlight all occurrences of characters not featuring the Arial orTimes New Roman Font

A

andreas

Dear Experts:

I would like to run a macro that performs the following tasks:

Highlight all occurrences of characters not featuring the Arial or
Times New Roman Font in the main document story. Is this possible?

Help is much appreciated. Thank you very much in advance. 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
 
T

Tony Jollans

This highlights everything and then removes it from Arial and Times New
Roman:

ActiveDocument.Content.HighlightColorIndex = wdYellow
With ActiveDocument.Content.Find
.Replacement.Highlight = False
.Font.Name = "Arial"
.Execute Replace:=wdReplaceAll
.Font.Name = "Times New Roman"
.Execute Replace:=wdReplaceAll
End With
 
A

andreas

This highlights everything and then removes it from Arial and Times New
Roman:

    ActiveDocument.Content.HighlightColorIndex = wdYellow
    With ActiveDocument.Content.Find
        .Replacement.Highlight = False
        .Font.Name = "Arial"
        .Execute Replace:=wdReplaceAll
        .Font.Name = "Times New Roman"
        .Execute Replace:=wdReplaceAll
    End With

--
Enjoy,
Tony

 www.WordArticles.com









- Show quoted text -

Hey Tony,

I really appreciate your professional help. Thank you very much. It is
working as desired. Great job. 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









- Show quoted text -

Hey Dough,

thank you for your quick help. My question was to highlight every
character/word of a document with exception of Times New Roman and
Arial formatted characters, not just Arial. I am sure you accidentally
overlooked that. No problem, since Tony Jollans code (see below) works
just fine. Thank you again. Regards, Andreas
Tony
 
D

Doug Robbins - Word MVP

OK, I did overlook that (I thought it was just a re-post of your earlier
question) I would like to know why you think that the macro that I posted
in response to that question goes into an endless loop. It certainly does
not do that here.

--
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









- Show quoted text -

Hey Dough,

thank you for your quick help. My question was to highlight every
character/word of a document with exception of Times New Roman and
Arial formatted characters, not just Arial. I am sure you accidentally
overlooked that. No problem, since Tony Jollans code (see below) works
just fine. Thank you again. Regards, Andreas
Tony
 
A

andreas

OK, I did overlook that (I thought it was just a re-post of your earlier
question)  I would like to know why you think that the macro that I posted
in response to that question goes into an endless loop.  It certainly does
not do that here.

--
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 Dough,

thank you for your quick help. My question was to highlight every
character/word of a document with exception of Times New Roman and
Arial formatted characters, not just Arial. I am sure you accidentally
overlooked that. No problem, since Tony Jollans code (see below) works
just fine. Thank you again. Regards, Andreas
Tony- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Hey Doug,

I tried it out on other documents and - indeed - it is running fine.
BUT, now HERE IT COMES: If the document ENDS in one or more BLANK
PARAGRAPHS(formatted with the Arial font), the macro falls into an
endless loop. On documents with no blank paragraphs (formatted with
Arial) at the end, the macro runs just fine. Is it possible for you to
change the macro with this in mind?

Regards, Andreas
 
A

andreas

This highlights everything and then removes it from Arial and Times New
Roman:

    ActiveDocument.Content.HighlightColorIndex = wdYellow
    With ActiveDocument.Content.Find
        .Replacement.Highlight = False
        .Font.Name = "Arial"
        .Execute Replace:=wdReplaceAll
        .Font.Name = "Times New Roman"
        .Execute Replace:=wdReplaceAll
    End With

--
Enjoy,
Tony

 www.WordArticles.com









- Zitierten Text anzeigen -

Hey Tony,

there is one more thing, I would like to ask you. Before running this
macro I would like to check whether all of the characters in the Word
document are neither Times New Roman nor Arial formatted. In this case
the macro is to exit.

Regrettably the expression I used for this purpose (.font.name = Arial
and font.name = Times new Roman) is apparently an "OR" function. How
am I to change it to an "And" condition, i.e. only in cases where all
of the characters of a document are neither "Arial" nor "Times
New Roman" formatted, the macro is to exit.

With ActiveDocument.Content.Find
.Font.Name = "Arial"
.Font.Name = "Times New Roman"
If Not .Execute Then
MsgBox "there are no characters formatted with Arial or Times
New Roman in the document" & vbCrLf & _
"Macro will exit", vbCritical, "Neither Arial nor Times New
Roman formatted characters in this doc!"
Exit Sub
End If
End With


Thank you very much in advance should you be ready to answer it
although the actual answer has already been answered sufficiently.
Regards, Andreas
 
T

Tony Jollans

Hi Andreas,

Sorry, but there is no way to look for two fonts (or the absence of two
fonts) in a single operation. You must do two separate operations, which is
what the code is doing already.

I can see whay you want this - to avoid the user having to scan the document
for un-highlighted text - but all you can do is catch the event afterwards,
perhaps like this:

Application.ScreenUpdating = False
ActiveDocument.Content.HighlightColorIndex = wdYellow
With ActiveDocument.Content.Find
.Replacement.Highlight = False
.Font.Name = "Arial"
.Execute Replace:=wdReplaceAll
.Font.Name = "Times New Roman"
.Execute Replace:=wdReplaceAll
.ClearFormatting
.Highlight = False
If .Execute = False Then
.Parent.HighlightColorIndex = wdNone
MsgBox "There are no characters formatted with " & _
"Arial or Times New Roman in the document" & _
vbNewLine & "Macro will exit", vbCritical, _
"Neither Arial nor Times New Roman formatted " & _
"characters in this doc!"
End If
End With
 
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
If Selection.End <> ActiveDocument.Range.End Then
Selection.Range.HighlightColorIndex = wdYellow
Selection.Collapse wdCollapseEnd
Else
Exit Do
End If
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

OK, I did overlook that (I thought it was just a re-post of your earlier
question) I would like to know why you think that the macro that I posted
in response to that question goes into an endless loop. It certainly does
not do that here.

--
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 Dough,

thank you for your quick help. My question was to highlight every
character/word of a document with exception of Times New Roman and
Arial formatted characters, not just Arial. I am sure you accidentally
overlooked that. No problem, since Tony Jollans code (see below) works
just fine. Thank you again. Regards, Andreas
Tony- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Hey Doug,

I tried it out on other documents and - indeed - it is running fine.
BUT, now HERE IT COMES: If the document ENDS in one or more BLANK
PARAGRAPHS(formatted with the Arial font), the macro falls into an
endless loop. On documents with no blank paragraphs (formatted with
Arial) at the end, the macro runs just fine. Is it possible for you to
change the macro with this in mind?

Regards, Andreas
 
A

andreas

Hi Andreas,

Sorry, but there is no way to look for two fonts (or the absence of two
fonts) in a single operation. You must do two separate operations, which is
what the code is doing already.

I can see whay you want this - to avoid the user having to scan the document
for un-highlighted text - but all you can do is catch the event afterwards,
perhaps like this:

    Application.ScreenUpdating = False
    ActiveDocument.Content.HighlightColorIndex = wdYellow
    With ActiveDocument.Content.Find
        .Replacement.Highlight = False
        .Font.Name = "Arial"
        .Execute Replace:=wdReplaceAll
        .Font.Name = "Times New Roman"
        .Execute Replace:=wdReplaceAll
        .ClearFormatting
        .Highlight = False
        If .Execute = False Then
            .Parent.HighlightColorIndex = wdNone
            MsgBox "There are no characters formatted with " & _
                   "Arial or Times New Roman in the document" & _
                   vbNewLine & "Macro will exit", vbCritical, _
                   "Neither Arial nor Times New Romanformatted " & _
                   "characters in this doc!"
        End If
    End With

--
Enjoy,
Tony

 www.WordArticles.com

Hey Tony,

exactly what I wanted. Thank you very much for your terrific help. I
really appreciate it. 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
        If Selection.End <> ActiveDocument.Range.End Then
            Selection.Range.HighlightColorIndex = wdYellow
            Selection.Collapse wdCollapseEnd
        Else
            Exit Do
        End If
    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 Doug,

I tried it out on other documents and - indeed - it is running fine.
BUT, now HERE IT COMES: If the document ENDS in one or more BLANK
PARAGRAPHS(formatted with the Arial font), the macro falls into an
endless loop. On documents with no blank paragraphs (formatted with
Arial) at the end, the macro runs just fine. Is it possible for you to
change the macro with this in mind?

Regards, Andreas- Hide quoted text -

- Show quoted text -


Dear Doug,

that's it! It is working now. Thank you very much for your
professional 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