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