Instructor PPTX VBA - Standardize the PPTX Slide Deck "Title" position, font, width and other formatting settings

Dealing with PowerPoint slide deck "Title" Insanity

Here is a script that will:

  • loop through each slide you have selected in your presentation
  • detects all shapes with TextFrames
    • it attempts to characterize them for the probability one is actually the intended title
      • it uses font size, frame width, height and proximity to the top of the slide
      • sometimes a slides will not have a textFrame with the name "title" or worse...
        • will have multiple TextFrames with the name "title" but are not a title but an integral part of your slides presented data, and cannot be moved
  • once a probable title has been detected, the script will relocate and apply consistent formatting across all selected slides
Sub positionTitleTxtBoxallslide()

    Dim oSld As Slide
    Dim oShp As Shape
    
    For Each oSld In ActiveWindow.Selection.SlideRange
        Dim x As Long
        For x = oSld.Shapes.Count To 1 Step -1
            Set oShp = oSld.Shapes(x)
            If oShp.HasTextFrame = True Then
                If oShp.Name Like "Titl*" And _
                    oShp.TextFrame.TextRange.Font.Size >= 28 And _
                    oShp.Width > 800 And _
                    oShp.Height < 200 _
                Then
                    Debug.Print "found likely candidate, moving shape"
                    SetTextFrameSettings oShp

                Else
                    If oShp.Top < 20 And oShp.Width > 800 And oShp.Height < 200 Then
                        Debug.Print "found likely candidate without correct title, moving shape"
                        SetTextFrameSettings oShp

                    End If
                End If
            End If
        Next x
    Next oSld

End Sub

Sub SetTextFrameSettings(myShp)
    myShp.Left = 41
    myShp.Top = 0.02
    myShp.TextFrame2.VerticalAnchor = msoAnchorTop
    With myShp.TextFrame.TextRange
        .Font.Size = 32
        .Font.Name = "Arial"
        .ParagraphFormat.Alignment = ppAlignLeft
    End With
End Sub

I am not a VBA expert, so if you have better ways to do this, please comment and I may update this example with better coding practices.

Comments

Popular posts from this blog

Advanced Network Security Troubleshooting and Solutions v22.411 (ANSTS)

Arubanetworks Webgate - Copy and Paste instructions