0

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
Oran G. Utan
  • 455
  • 1
  • 2
  • 10

1 Answers1

2

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.

John Korchok
  • 4,723
  • 2
  • 11
  • 20
  • @ JohnKorchok thank you, I edited as per suggestion, however I am getting an error exactly in the line you asked clarification about. I will post another question regarding that and once the full code is running I will upvote your answer (which I am sure will work), is that fine for you? – Oran G. Utan Feb 23 '22 at 18:01
  • Please read the link in my post "Can I ask only one question per post?" I've answered your original question. Then you edited your question to include a second one. Stack Overflow is not about asking a series of questions, then awarding one upvote for the series. One question, one answer, one upvote. Thanks for being a considerate StackOverflow user! – John Korchok Feb 23 '22 at 19:16
  • @ JohnKorchok I did not edit the question: I left it as it is. I followed your instructions above that said to post another question in case I needed further clarifications, so there is another one mentioning the MasterPlaceholder line. I was not sure if I should ask here in the comment sections as you may consider this as asking two questions in one post. I wanted top upvote this one but since I am not able to see the results yet I would not know if I should mark it as solved. – Oran G. Utan Feb 23 '22 at 19:24
  • @ JohnKorchok I found the way to refer to the MasterPlaceHolder and I could see your correction worked, so I upvoted your solution. – Oran G. Utan Feb 23 '22 at 20:15