Insert a new rectangle in PowerPoint VBA

I am trying to paste a picture from excel into the rectangle of a powerpoint slide. However, since I don't want to use any current existing rectangle I want to add the rectangle and then paste my enhanced metafile into it from excel. I currently can paste and do all that just need to know how to add the rectangle.

I need the rectangle because when you paste a picture into it, it automatically re-sizes it for you.

this is the only code  i could find to add the rectangle however, it also adds the title slide and will not add a new rectangle if it already exists on the page.

ActiveWindow.Selection.SlideRange.Layout = ppLayoutText
tchristie33Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
atomsheepConnect With a Mentor Commented:
Actually, from Excel VBA, click the Tools menu, then References, and check the Microsoft PowerPoint Object Library. Then in Excel's code, try something like:

Dim ppt As New PowerPoint.Application
ppt.ActiveWindow.Selection.SlideRange.Layout = ppLayoutLargeObject

Just worked for me.
0
 
werafaCommented:
Use the macro recorder  and have a look at the code
0
 
tchristie33Author Commented:
how do i use PP to just insert the rectangle then?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
dandrakaCommented:
Ensure that the presentation is in normal view, not slide master view...try the code below:

ActiveWindow.ViewType = ppViewSlide
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeRectangle, 116.25, 128.25, 72#, 72#).Select
0
 
tchristie33Author Commented:
The problem with that rectangle is that you can't paste an enhanced metafile into it so that it will be automatically size to the shape of the rectangle. I need to insert the box that shows up with you do the slide layout for ppLayoutLargeObject. However, I can't just add a slide and do that layout since a current layout will already exist on the slide and I just want to add the Layoutlargebject rectangle whether it already exists or not. Does that make sense?
0
 
atomsheepCommented:
The code:

ActivePresentation.Slides(1).Layout = ppLayoutLargeObject

works for me to insert the large layout object into slide 1 whether or not an existing layout is there or not...
0
 
tchristie33Author Commented:
That is essentially what I want to do. However, when I try to execute that code from excel vb I get this error "slide.layout : invalid enumeration value" how do I get around that?
0
 
atomsheepCommented:
Hmm, it works fine for me. I run the code from within PowerPoint VBA though, not from Excel.
0
 
tchristie33Author Commented:
Are you able to show me how to do it from Excel?
0
 
atomsheepCommented:
I have a feeling it's not possible to call Slide.Layout from Excel because this is out of Excel's namespace.
0
 
tchristie33Author Commented:
ahhh bummer....are there any other options? And are you positive about that?
0
 
atomsheepCommented:
Oh and both PowerPoint and Excel need to be open.
0
 
tchristie33Author Commented:
Great! Could you also tell me how to change the size of the ppLayoutLarge object as well?
0
 
atomsheepCommented:
ActiveWindow.Selection.SlideRange.Master.Shapes(1).Height = 100

This should change the height of the large layout object. Substitute .Height for .Width to change the width, .Left to change the x coordinate of the left top corner, and .Top to change the y coordinate of the left top corner. This will work if you have only the ppLayoutLargeObject on the slide (hence the first item in the Shapes collection).
0
All Courses

From novice to tech pro — start learning today.