Share via

Use VBA to change font size in powerpoint

Anonymous
2013-06-02T08:51:41+00:00

I hope to change all font sizes in all my slide, but encountered difficulties in writing the code. Here is my draft. Thank you for your help in advance.

Sub ChangeFontSize()

Dim sld As Slide

Dim I As Long

On Error Resume Next

        For I = 1 To ??  'how can I loop the slides from page 1 to the end of the slides.

            .Font.Size = 26    'how to correct this??

     Next I

     Next sld

End Sub

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2013-06-02T12:00:40+00:00

Here is how I would code it:

Sub ChangeFontSize()

Dim sld As Slide

Dim shp As Shape

For Each sld In ActivePresentation.Slides

For Each shp In sld.Shapes

If shp.HasTextFrame = True Then

If shp.TextFrame.HasText = True Then

If shp.TextFrame.TextRange.Font.Size = 24 Then

shp.TextFrame.TextRange.Font.Size = 28

End If

End If

End If

Next

Next

End Sub

Hope this helps

Was this answer helpful?

5 people found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2013-06-02T14:05:02+00:00

The code Rich Michaels provided will work for all native PowerPoint shapes. For handling text within tables and charts, you will need to extend it further if you need it.

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-09-26T06:31:06+00:00

    Hello

    I think this code is similar, however it does give me out of range issues...  

    The specified value is out of range.

    can you help me figure out why?

    Sub positionTitleTxtBoxallslide()

    Dim oSld As Slide

    Dim oSh As Shape

    For Each oSld In ActiveWindow.Selection.SlideRange

        Dim x As Long

        For x = oSld.Shapes.Count To 1 Step -1

            Set oSh = oSld.Shapes(x)

            If oSh.TextFrame.TextRange.Font.Size <= 36 Then

                oSh.Left = 44

                oSh.Top = 0.02

                With oSh.TextFrame.TextRange

                   .Font.Size = 32

                   .Font.Name = "Casual"

                   .ParagraphFormat.Alignment = ppAlighnLeft

                End With

            End If

        Next x

    Next oSld

    End Sub

    thank you.

    Here is how I would code it:

    Sub ChangeFontSize()

    Dim sld As Slide

    Dim shp As Shape

    For Each sld In ActivePresentation.Slides

    For Each shp In sld.Shapes

    If shp.HasTextFrame = True Then

    If shp.TextFrame.HasText = True Then

    If shp.TextFrame.TextRange.Font.Size = 24 Then

    shp.TextFrame.TextRange.Font.Size = 28

    End If

    End If

    End If

    Next

    Next

    End Sub

    Hope this helps

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2017-09-26T13:17:52+00:00

    There's a typo in ppAlignLeft

    You also need to be sure you have slides selected

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-06-02T14:50:29+00:00

    Thank you Rich Michaels. The code works very sell.

    Was this answer helpful?

    0 comments No comments