Highlight all occurrences of different font formatting in footnotes

A

andreas

Dear Experts:
below macro highlights all occurrences of different font formatting in
footnotes. In this example the built-in "footnote text" style has the
font "Times New Roman". The macro highlights all footnotes where "non-
Times-New-Roman" font formatting on some words has been applied.

Now my questions:
1.
the macro highlights the WHOLE footnote where an occurence of "Non-
Times-New-Roman" font formatting is found. Is itpossible to just
highlight the words/characters that have been differently formatted?
2.
Is it possible to have Word show a msgbox after running the macro
saying:
Highlighting has been applied or no occurrences of a different
footnote font found

Help is appreciated. Thank you very much in advance.

Regards, Andreas



Dim myFootnote As Footnote

For Each myFootnote In ActiveDocument.Footnotes
If Not myFootnote.Range.Font.Name = "Times New Roman" Then
myFootnote.Range.HighlightColorIndex = wdBlue
End If
Next myFootnote

End Sub
 
D

Doug Robbins - Word MVP

This will highlight the first occurence of non Times New Roman font
formatting in each footnote and also display the required message.

As it stands, it does not highlight non-contiguous ranges within a single
footnote that are not formatted with Times New Roman. It could probably be
developed further to do that.

Dim myFootnote As Footnote
Dim myrange As Range
Dim i As Long, j As Long
Dim Flag As Boolean
Flag = False

For Each myFootnote In ActiveDocument.Footnotes
If Not myFootnote.Range.Font.Name = "Times New Roman" Then
Set myrange = myFootnote.Range.Duplicate
For i = 1 To myrange.Characters.Count
If Not myrange.Characters(i).Font.Name = "Times New Roman"
Then
myrange.start = myrange.start + i - 1
Flag = True
For j = 1 To myrange.Characters.Count
If myrange.Characters(j).Font.Name = "Times New
Roman" Then
myrange.End = myrange.start + j - 1
myrange.HighlightColorIndex = wdBlue
Exit For
End If
Next j
Exit For
End If
Next i
End If
Next myFootnote
If Flag = True Then
MsgBox "Formatting has been applied to footnotes with text other
than Times New Roman."
Else
MsgBox "All footnotes are formatted with Times New Roman."
End If

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

Helmut Weber

Hi Andreas,

how about the idea,
to highlight all occurences
of Times New Roman and
reverse the highlighting afterwards?

Sub Test400A()
Dim rFoot As Footnote
Dim rTmp As Range
For Each rFoot In ActiveDocument.Range.Footnotes
If Not rFoot.Range.Font.name = "Times New Roman" Then
Set rTmp = rFoot.Range
With rTmp.Find
.Format = True
.Font.name = "Times New Roman"
While .Execute
rTmp.HighlightColorIndex = wdYellow
Wend
End With
Set rTmp = rFoot.Range
With rTmp.Find
.Format = True
.Highlight = False
While .Execute
rTmp.HighlightColorIndex = wdBlue
rTmp.Collapse
Wend
End With
Set rTmp = rFoot.Range
With rTmp.Find
.Format = True
.Font.name = "Times New Roman"
While .Execute
rTmp.HighlightColorIndex = wdNoHighlight
Wend
End With
End If
Next
End Sub
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
K

Klaus Linke

Hi Andreas,

The "Footnote Text" has nothing highlighted originally?

You might do (1.) with two replacements:
-- Replace "Footnote Text" wilth .HighlightColorIndex = wdBlue
-- Replace ("Footnote Text" + Font="Times New Roman") with
..HighlightColorIndex = wdNone

For (2.) you could then search for "Footnote Text" + .HighlightColorIndex =
wdBlue and report whether anything was found.

Regards,
Klaus
 
A

andreas

Hi Andreas,

how about the idea,
to highlight all occurences
of Times New Roman and
reverse the highlighting afterwards?

Sub Test400A()
Dim rFoot As Footnote
Dim rTmp As Range
For Each rFoot In ActiveDocument.Range.Footnotes
   If Not rFoot.Range.Font.name = "Times New Roman" Then
      Set rTmp = rFoot.Range
      With rTmp.Find
         .Format = True
         .Font.name = "Times New Roman"
         While .Execute
            rTmp.HighlightColorIndex = wdYellow
         Wend
      End With
      Set rTmp = rFoot.Range
      With rTmp.Find
         .Format = True
         .Highlight = False
         While .Execute
            rTmp.HighlightColorIndex = wdBlue
            rTmp.Collapse
         Wend
      End With
      Set rTmp = rFoot.Range
      With rTmp.Find
         .Format = True
         .Font.name = "Times New Roman"
         While .Execute
            rTmp.HighlightColorIndex = wdNoHighlight
         Wend
      End With
   End If
Next
End Sub
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Hey Helmut,

as always, thank you very much. The code is exactly what I wanted. I
took the "boolean part" of Doug Robbin's code

(If Flag = True Then
MsgBox "Formatting has been applied to footnotes with text
other than Times New Roman."
Else
MsgBox "All footnotes are formatted with Times New Roman."
End If)

to complete your code. Thank you for your terrific help.
Regards, Andreas
 
A

andreas

Hi Andreas,

The "Footnote Text" has nothing highlighted originally?

You might do (1.) with two replacements:
-- Replace "Footnote Text" wilth .HighlightColorIndex = wdBlue
-- Replace ("Footnote Text" + Font="Times New Roman") with
.HighlightColorIndex = wdNone

For (2.) you could then search for "Footnote Text" + .HighlightColorIndex =
wdBlue and report whether anything was found.

Regards,
Klaus











- Show quoted text -

Hey Claus,

Yes you are right. I tried it. This is another way to solve my
problem. Thank you very much. Regards, Andreas
 
A

andreas

This will highlight the first occurence of non Times New Roman font
formatting in each footnote and also display the required message.

As it stands, it does not highlight non-contiguous ranges within a single
footnote that are not formatted with Times New Roman.  It could probablybe
developed further to do that.

Dim myFootnote As Footnote
Dim myrange As Range
Dim i As Long, j As Long
Dim Flag As Boolean
Flag = False

    For Each myFootnote In ActiveDocument.Footnotes
        If Not myFootnote.Range.Font.Name = "Times New Roman" Then
            Set myrange = myFootnote.Range.Duplicate
            For i = 1 To myrange.Characters.Count
                If Not myrange.Characters(i).Font.Name ="Times New Roman"
Then
                    myrange.start = myrange.start + i - 1
                    Flag = True
                    For j = 1 To myrange.Characters.Count
                        If myrange.Characters(j).Font.Name = "Times New
Roman" Then
                            myrange.End = myrange.start + j - 1
                            myrange.HighlightColorIndex = wdBlue
                            Exit For
                        End If
                    Next j
                    Exit For
                End If
            Next i
        End If
    Next myFootnote
    If Flag = True Then
        MsgBox "Formatting has been applied to footnotes with textother
than Times New Roman."
    Else
        MsgBox "All footnotes are formatted with Times New Roman."
    End If

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

Dear Doug,
thank you for your valuable help. It works just fine. As you stated,
the macro should be developed further to account for non-contiguous
ranges. Incidentally, Helmut Weber did this as you can see below. So
thank you to both of you for your terrific 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