Home > Software design >  How to select specific placeholder in Layout - Slide Master
How to select specific placeholder in Layout - Slide Master

Time:02-24

I am trying to write a macro that resizes placeholders within layouts, but I do not know how to indicate them to VBA. I have tried several ways, and with the below code I get Method or data member not found. I also tried adding two variables (SM As Design and CL AS CustomLayout) and then point to CL with "SlideMaster.CustomLayouts(4).Shapes.Placeholders("Content Placeholder 2").Name" (as in Handling a Shape by its Placeholder Name in PowerPoint), but then I get Object Required error in the line where I set MasterPlaceHolder.

Could someone please advise?

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 HorizontalDistance As Single
Dim VerticalDistance As Single


HorizontalDistance = 360
VerticalDistance = 144



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


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



    With ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4)

        ActivePresentation.Designs(1).Shapes.Placeholders.FindByName("Content Placeholder 2").Select 'here I get the error
        
            With Selection
            
                .Left = LeftLimit
                .Width = (DrawingAreaWidth / 2) - HorizontalDistance
                
            End With
    
    End With


End Sub

CodePudding user response:

I am answering the question you have posted. Please give this an upvote if it answers your question. After I answer, you will have other questions. Please post those in new threads. Can I ask only one question per post?

Do you have Intellisense turned on the the VB editor (Tools>Options>Editor>Auto Syntax Check)? That would highlight some of the errors in your code.

Replace the section starting with With ActivePresentation with the following code:

For Each oShape In ActivePresentation.Designs(1).SlideMaster.CustomLayouts(4).Shapes
    If oShape.Name = "Content Placeholder 2" Then
        oShape.Left = LeftLimit
        oShape.Width = (DrawingAreaWidth / 2) - HorizontalDistance
    End If
Next oShape

For your followup question(s), please define what MasterPlaceholder is supposed to be referencing. A placeholder on the Slide Master? The placeholder that you're going to modify? It's not clear from your existing code.

  • Related