Home > OS >  How to refer to a placeholder of the Slide Master
How to refer to a placeholder of the Slide Master

Time:02-25

I am trying to get the dimensions of the main placeholder in the Slide Master Text placeholder 2 - that in the code would be "MasterPlaceholder" - (whose size has been modified, and the new dimensions are pulled only in the third Layout, as shown in the picture) and set them as the basis for the resizing of all other placeholders in the other Layouts. Given a certain distance between Heading's placeholders and Body/Generic placeholders, I would like to loop through all Layouts and apply the new size.

However, I do not know how to point to this shape and I tried several ways (also "ActivePresentation.Designs(1).SlideMaster.Shapes.Placeholders.("Text Placeholder 2")", "ActivePresentation.Designs(1).SlideMaster.Shapes.Placeholders.Name("Text Placeholder 2")", but I cannot find a way to point it without errors.

Could someone please let me know how to properly refer to it? This would also help me find a way to refer to "PlcHlder", which would be the shape to be ridimensioned

enter image description here

Sub PlaceHolderResizer()
Dim LeftLimit As Single
Dim TopLimit As Single
Dim RightLimit As Single
Dim BottomLimit As Single
Dim DrawingAreaWidth As Single
Dim DrawingAreaHeight As Single
Dim MasterPlaceholder As Shape
Dim PlcHldr As Shape
Dim oShape As Shape
Dim HorizontalDistance As Single
Dim VerticalDistance As Single
Dim HeadingToPlaceholder As Single


HorizontalDistance = 360
VerticalDistance = 144
HeadingToPlaceholder = 144



Set MasterPlaceholder = SlideMaster.Shapes.Placeholders.Name("Text Placeholder 2")




     LeftLimit = MasterPlaceholder.Left
     TopLimit = MasterPlaceholder.Top
     RightLimit = MasterPlaceholder.Left   oShape.Width
     BottomLimit = MasterPlaceholder.Top   oShape.Height
     DrawingAreaWidth = MasterPlaceholder.Width
     DrawingAreaHeight = MasterPlaceholder.Height



For Each oShape In ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4).Shapes



    If oShape.Name = "Content Placeholder 2" Then
    
        oShape = PlcHldr
        oShape.Left = LeftLimit
        oShape.Width = (DrawingAreaWidth / 2) - HorizontalDistance
    End If
Next oShape


End Sub

CodePudding user response:

As in https://docs.microsoft.com/en-us/office/vba/api/powerpoint.placeholders, I assigned the Index 2 to the shape (because there is a title, which would be 1) and finally the placeholder was re-dimensioned (the size at this moment does not matter, since it is something I will fix later). The code still needs great improvement, but at least I saw some action in the item I was referring to.

I will have to find a way to point to the placeholder by name somehow, something more talkative than an index number.

Sub PlaceHolderResizer()
Dim LeftLimit As Single
Dim TopLimit As Single
Dim RightLimit As Single
Dim BottomLimit As Single
Dim DrawingAreaWidth As Single
Dim DrawingAreaHeight As Single
Dim MasterPlaceholder As Shape
'Dim PlcHldr As Shape
Dim oShape As Shape
Dim HorizontalDistance As Single
Dim VerticalDistance As Single
Dim HeadingToPlaceholder As Single


HorizontalDistance = 72
VerticalDistance = 144
HeadingToPlaceholder = 144



Set MasterPlaceholder = ActivePresentation.SlideMaster.Shapes.Placeholders(2) ' here is how I should have called it




     LeftLimit = MasterPlaceholder.Left
     TopLimit = MasterPlaceholder.Top
'     RightLimit = MasterPlaceholder.Left   oShape.Width
'     BottomLimit = MasterPlaceholder.Top   oShape.Height
     DrawingAreaWidth = MasterPlaceholder.Width
     DrawingAreaHeight = MasterPlaceholder.Height



For Each oShape In ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4).Shapes



    If oShape.Name = "Content Placeholder 2" Then
    
'        oShape = PlcHldr
        oShape.Left = LeftLimit
        oShape.Width = DrawingAreaWidth - HorizontalDistance
    End If
Next oShape


End Sub

CodePudding user response:

On the slide master, there can only be one text placeholder. So you can use the placeholder Type property to identify it and get its name:

Sub GetPlaceHolderName()
    Dim oShape As Shape
    
    For Each oShape In ActivePresentation.SlideMaster.Shapes
        If oShape.PlaceholderFormat.Type = ppPlaceholderBody Then
            MsgBox oShape.Name
        End If
    Next oShape
End Sub

Looping through object collections to get names is par for the course with PowerPoint VBA, you'll use that technique very often.

  • Related