Search code examples
vbareplacefontspowerpoint

Trouble Replacing Fonts in PowerPoint Presentation


I cannot change (i.e., "replace") two of the fonts used in a presentation I inherited that are giving issues to our users.

I have the presentation set to embed fonts, but as I do not have the one in question, I can't fix it like I normally would (i.e., usually having the font in question and opening the file and closing it again embeds the fonts and there are no more issues.)

The font in question in this case is called "Times" (not "Times New Roman", just "Times"), which I believe is an ancient PostScript font, if I'm not mistaken, which would be an issue since, from what I understand, PowerPoint does not support PostScript fonts.

At any rate, I want to replace the font with "Arial", which I know is usually easily accomplished with Replace > Replace Font . . . however, it's not taking for some reason in this file. I'll tell PowerPoint to replace it, it seems to do something, and then . . . no change.

SO. . . I headed to Google and tried a few things (One possibly mentioned by PPTools was converting the file to HTML and back, which is said to fix (i.e., "remove") some Asian and other unsupported fonts from presentations. But as I couldn't figure out how to save a presentation as a Web Page in O365 offline (PowerPoint 2019), it was a no go (there appears to be no option that I can find to either "Save As" or "Export" HTML or a Web Page, as was recommended. I therefore started looking VBA.

My first try was this, as I found was originally used to change Far East Fonts to Arial:

Sub ChgFarEastFontsToArial()
    Dim oSh As Shape
    Dim oSl As Slide

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If oSh.HasTextFrame Then
                oSh.TextFrame.TextRange.Font.NameFarEast = "Arial"
            End If
        Next
    Next

    For Each oSh In ActivePresentation.SlideMaster.Shapes
        If oSh.HasTextFrame Then
            oSh.TextFrame.TextRange.Font.NameFarEast = "Arial"
        End If
    Next

    If ActivePresentation.HasTitleMaster Then
        For Each oSh In ActivePresentation.TitleMaster.Shapes
            If oSh.HasTextFrame Then
                oSh.TextFrame.TextRange.Font.NameFarEast = "Arial"
            End If
        Next
    End If

End Sub

It runs without error when I don't change anything, but since I wasn't actually looking to change Far East fonts, it didn't help me.

My next try was this:

Sub ReplaceFontToArial()
  Dim objSingleWord As Range
  Dim objDoc As Presentation

  Set objDoc = ActivePresentation

  With objDoc
    For Each objSingleWord In .Words
      If objSingleWord.Font.Name = "Times" Then 
        objSingleWord.Font.Name = "Arial"
      End If
    Next
  End With
End Sub

But, it errors out highlighting ObjSingleWord As Range and stating, Compile error: User-defined type not defined.

Then, upon a suggestion from the Microsoft VBA reference docs, I tried:

Sub ReplaceFontToArial()
  With Application.ActivePresentation
    .Fonts.Replace Original:="Times", Replacement:="Arial"
  End With
End Sub

But this errors out with a Run-time error '424': Object required.

I'm about out of thoughts to fix this problem. Any thoughts on how I can change out this crazy font would be amazing!! (Also advice on why my scripts above are not working would also be helpful.)


FYI, in case it helps, fonts that will not be replaced are:

Times Unsupported font file format (AAT), Times Bold Unsupported font file format (AAT), Times Italic Unsupported font file format (AAT), Times Bold Italic Unsupported font file format (AAT), and Noto Sans Symbols.


Solution

  • Times is a Mac font (AAT is Apple Advanced Typography). My preferred technique with stubborn fonts is to change the file ending to .zip, unzip the file to OOXML, then use a text editor like NotePad++ to run a find and replace on all files.

    Find: typeface="Times" Replace: typeface="Arial"

    Then rezip and rename back to .pptx. Make a copy of the file to experiment. This method also works great on changing PowerPoint language settings.