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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.