Trying to find a shape with one fontname and replace its font to another

时间:2017-12-18 05:19:31

标签: vba powerpoint-vba

I wrote a code to ask user input a fontname and then use VBA to search the whole presentation for shapes that bears this font and replace to another.

However, my code somehow doesn't work. I figure the reason is this line "If sh.TextFrame.TextRange.Font.Name = searchFont Then" The fontname return from the user input is just text, but this line need it to be within " ". (eg. "Arial")

if anyone has a solution to this, please kindly help me. Thanks in advance

Sub ReplaceFont()

Dim sld As Slide
Dim sh As Shape
Dim searchFont As String

searchFont = InputBox("Please enter font to search.", "Font Search Function")

On Error Resume Next


For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes
If sh.HasTextFrame = True Then
If sh.TextFrame.HasText = True Then

    If Ucase(sh.TextFrame.TextRange.Font.Name) = Ucase(searchFont) Then
        With sh.TextFrame.TextRange.Font
        .Name = "Arial"
        End With

    End If
End If
End If
Next
Next

End Sub

0 个答案:

没有答案