vbapowerpoint

Using VBA in PowerPoint to change font


How do I use VBA to make the font consistent throughout a PowerPoint presentation?

I'm new to VBA, so the code I used could be completely wrong but here it is:

Sub FontChange()

  Dim sld As Slide
  Dim shp As Shape

   For Each sld In ActivePresentation.Slides
       For Each shp In sld.Shapes
       shp.TextFrame.TextRange.Font

         .Size = 12

         .Name = "Bauhaus 93"

         .Bold = False

         .Color.RGB = RGB(255, 127, 255)
    Next shp
   Next sld
End Sub

Thanks in advance for the help.


Solution

  • A few mods to Wayne's version in the event that you want to change text that's not in placeholders. And a few tests to make sure that the shape in question a) CAN contain text (shapes like lines cannot) and if so b) that it HAS some text to modify.

    Option Explicit
    
    Sub FontChange()
    
    Dim sld As Slide
    Dim shp As Shape
    
    For Each sld In ActivePresentation.Slides
        For Each shp In sld.Shapes
        If shp.HasTextFrame Then  ' Not all shapes do
        If shp.TextFrame.HasText Then  ' the shape may contain no text
            With shp.TextFrame.TextRange.Font
                .Size = 12
                .Name = "Bauhaus 93"
                .Bold = False
                .Color.RGB = RGB(255, 127, 255)
            End With
        End If
        End If
        Next shp
    Next sld
    End Sub