How to access the interface of an OLE object inside Powerpoint
Posted on 2003-03-04
First a bit of background:
If you launch Microsoft Powerpoint, create an empty presentation, add an empty slide, insert an Object of type "Microsoft Word Document".
You are now in edit mode in the OLE document ie Word. Type a bit of text, just enough to make a line without wrapping to the next line.
Press the escape key. You're back in the powerpoint environment. Click on the object you have just created and resize it down in width using the mouse.
What you can see is that the text is compressed. IE the shape is scaled rather than the object. Use undo to get it back to its previous size.
Now right-click on the object and select Object->Edit. You're back in edit mode. Use the mouse once again to resize the object. What you should see is the text wrapping around to the next line as the control gets smaller. keep it smaller and press escape.
Now you're back in powerpoint with the control smaller and the text wrapped around.
Ok, so all this to make a clear point. There are two sizes when dealing with an object. The Object size and the Shape size. In Edit mode, you resize the object and the text gets reformatted. In normal mode, you resize the shape and the image of the object gets stretched/compressed.
Now let's talk programming:
I need to insert text into a powerpoint presentation programatically. I have this code:
shape = shapes->AddOLEObject(
if (shape == NULL) return S_FALSE;
This inserts fine but the height and width parameters create a streched/compressed image rather than setting the OLE object size.
So I need to call AddOLEObject with Height and Width set to 0 (that's OK) then I need to resize the Object, not the shape.
Now the question:
Given a PowerPoint::ShapePtr shape, I can call shape->PutHeight() and shape->PutWidth() but that resizes the Shape, how do I resize the object iei how to I simulate programmatically going to "object/Edit" context menu and resizing the object while in edit mode?
I can call shape->OLEFormat and I get a PowerPoint::OLEFormatPtr instance and then I can call Object and I get a IDispatchPtr on the Object (or so I think) but is that the right where and where do I go from there to resize the object ?
Any code, C++, MFC, ATL, VB, VBA will do. I just need so info on the interface(s) to use, I guess.