VBA for pasting tables to PowerPoint - shape problem

lukasz_rz

New Member
Joined
Oct 13, 2013
Messages
48
Hello.

I have a ppt with different shapes. And I have xls file with different tables and charts. My macro is copying different objects from xls to ppt - shape in ppt is replaced by the assigned object from xls.

First I take the shape parameters:

SQL:
Set obj = pppres.Slides(sld(i)).Shapes(crt(i))
a = obj.Height
b = obj.Width
C = obj.Top
d = obj.Left

And then paste the object from xls and replace the shape (I delete the shape afterwards)

<select something in xls>
SQL:
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set myShapeRange = pppres.Slides(sld(i)).Shapes.Paste
     With myShapeRange
        .LockAspectRatio = msoFalse
        .Left = d
        .Top = C
       .Width = b
       .Height = a
    End With

By doing that I can put each table/chart/whatever exactly where I want in ppt. However, there is one thing I cannot do better - the objects size and shape. With my settings, each xls object inherits the size of the ppt shape. What I would like to do is to set up the top left corner (c,d) as the permanent value and then paste the object (with locked aspect ratio) into the shape. The condition is that the object cannot be bigger than a shape (however can be smaller).

This is not a big deal with charts and tables, but it makes things worse with pivot tables - different amount of rows is causing the objects to look bad sometimes when pasted as shape. Is there anything I can change in the code to make it better?

Thanks in advance.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top