Font replacement

P

Peter Karlström

Hi

My customer requested a function to find and replace some fonts in their
documents.
I created one based on a recorded macro and it works fine for the
document body, but it doesn't find the fonts in the pageheader.
The function is a part of a COM-addin made with VB 6.

This is the basis of my routine:
<Start code sample>
Public Function CheckFonts(ByVal showMess As Boolean) As Boolean

Dim Fonts(3) As String
Dim i As Integer

On Error GoTo CheckFontsError
CheckFonts = False

Fonts(0) = "Fontname 1"
Fonts(1) = "Fontname 2"
Fonts(2) = "Fontname 3"

For i = 0 To UBound(Fonts)
With wrdApp.ActiveDocument.Content.Find
.ClearFormatting
.Font.Name = Fonts(i)
Do While .Execute(FindText:="", Forward:=True, Format:=True) =
True
CheckFonts = True
Exit Do
Loop
End With
If CheckFonts Then Exit For
Next

CheckFontsExit:

If CheckFonts Then MsgBox "Fonts to be replaced ar found in the
document!" & vbCrLf & "Replace them with the tool in the toolbar.", vbOKOnly,
App.ProductName & " Ver: " & App.Major & "." & App.Minor & "." & App.Revision

Exit Function

CheckFontsError:
CheckFonts = False
Resume CheckFontsExit

End Function
<End code sample>

Now, where do I go wrong?
I suspect the With... row but don't know exactly what.

Thanks in advance
 
P

Peter Karlström

Sorry about this.

With a little research the solution is to search each part of the document
in turns.

Like this:

First search ActiveDocument.StoryRanges(wdMainTextStory).Find
The search ActiveDocument.StoryRanges(wdFirstPageHeaderStory).Find
and so on.

Hope this will help someone more than me...
 

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