Search code examples
vbatextboxpowerpointpowerpoint-2016

How to change a specific textbox in a powerpoint slide master


I have a powerpoint that uses different Master layouts on the slide Master. Every time we do an update, a specific textbox on a specifc Master slides needs to be updated. I would like to do so with a macro.

IE I have a slide master with a Generic Title_Slide and 2 variations under that. It has a "Generic Bullet_slide" with 10 variations under that.

on the "Generic Bullet_Slide" there is a textbox that contains two lines: "CONFIG. MGR: [your name], [your code], [your phone #]" "FILE NAME: [name of file]"

every time we send the project out, we need to update the fields in [] manually. If we forget its bad news.

I have seen how to loop through all slides, then all shapes to find text boxes. Can I find a boxs that specifically has those words in it ("CONFIG. MGR:" and "FILE NAME:") ?

Can I search "layout" slides only? how do I target anything on the layout slide instead of a normal slide?

thanks a bunch.


Solution

  • You can use the object named 'ActivePresentation.Designs(x).SlideMaster.CustomLayouts' to access each custom-layout slide in SlideMaster Designs. (You can have more than 1 design in a presentation.)

    Accessing sub-objects in the custom-layout slides is just like dealing with those in the normal slides.

    I think you can try the following automation code:

    Option Explicit
    Option Compare Text 'Ignore Upper/Lower case
    
    Sub UpdateCustomLayouts()
    
        Dim DSN As Design
        Dim CL As CustomLayout
        Dim shp As Shape
        Dim mName As String, mCode As String, mPhone As String, fName As String
    
        'First, change following variables before running this macro
        mName = "Your name"
        mCode = "Your code"
        mPhone = "0123456789"
        fName = ActivePresentation.Name
    
        'Loop each customlayouts
        For Each DSN In ActivePresentation.Designs
            For Each CL In DSN.SlideMaster.CustomLayouts
                For Each shp In CL.Shapes
                    If shp.HasTextFrame Then
    
                        'find and update textboxes
                        With shp.TextFrame.TextRange
                            If .Text Like "CONFIG. MGR:*" Then
                                .Text = "CONFIG. MGR: " & mName & ", " & mCode & ", " & mPhone
                            ElseIf .Text Like "FILE NAME:*" Then
                                .Text = "FILE NAME: " & fName
                            End If
                        End With
    
                    End If
                Next shp
            Next CL
        Next DSN
    
    End Sub
    

    As I mentioned, first change variables like 'mName, mCode, mPhone, fName' before running.