Log in

View Full Version : Unable to Replace Certain Fonts



lemonbars
08-23-2019, 05:42 PM
I have a powerpoint presentation that I inherited that is causing some drama because of a few fonts, namely Times (not to be confused with Times New Roman) and Noto Sans Symbols that are showing up as "unsupported" for some of our users. These fonts need to be replaced throughout the presentation, wherever they may exist, but Replace > Replace Fonts is not working for these. There are a few things I have tried:


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()
Application.ActivePresentation.Fonts.Replace Original:="Times", Replacement:="Arial"
End Sub


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

I'm completely out of thoughts to fix this problem. Any help on how I can change out these crazy fonts and what I'm doing wrong would be amazing!!

Paul_Hossler
08-24-2019, 07:24 AM
Using PP 365 and the online Help:



You can also use the Replace Font option to change a font throughout your presentation. Here's how:


On the Home tab, in the Editing group, select Replace and then select Replace Fonts.
In the Replace Font dialog box, in the Replace field, select the font that you want to replace.
In the With field, select the font that you want to use, select Replace, and then select Close.



24852

It might be possible to automate that, but once it's converted, why bother?

lemonbars
08-24-2019, 04:44 PM
As I stated, Replace > Replace Fonts is not working for these particular fonts, which is sometimes a known issue for PPT. Therefore, I am seeking a programmatic way of ridding myself of this problem. What I have tried so far is not working, therefore I am seeking assistance, The only other answer I've been offered is that I might want to ZIP the presentation, unzip it, use an OOXML view to find the fonts, and using Notepad, replace the offending fonts with what they should be, zip it back up, and change the extension back to pptx. My concern with this is that OOXML fiddling has known to cause errors. Plus, if there is a programmatic way of doing this, wouldn't that be the way to go?

Paul_Hossler
08-24-2019, 05:18 PM
Sorry, misunderstood

Can you post a single slide presentation with the font problem

John Wilson
08-25-2019, 02:49 AM
Your vba code is not correct so first try


Sub ReplaceFontToArial()
Dim objDoc As Presentation
Dim oshp As Shape
Dim osld As Slide
Dim L As Long
Set objDoc = ActivePresentation
For Each osld In objDoc.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.HasText Then
With oshp.TextFrame.TextRange
For L = 1 To .Words.Count
Debug.Print .Words(L).Font.Name
If .Words(L).Font.Name = "Times" Then .Words(L).Font.Name = "Arial"
Next L
End With
End If
End If
Next oshp
Next osld
End Sub

Some fonts cannot be replaced so you may have to go down the XML route.

Try this:

Work on a cOPY!

Save as a PowerPoint XML file

Open in Notepad

Replace Times with Arial (or whatever)

Save
Open in PowerPoint and resave as a PPTX.