VBA to paste picture into PPT to a designated width or height whilst keeping aspect ratio

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
575
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I have some code which takes a range in excel (which changes in size) and then pastes it into powerpoint as a picture. I need some code that will copy the range and paste it as a picture to a specified width or height (one or the other). Whether the picture is sized to the specified width or height is based on its aspect ratio (which must be maintained). Put another way - if one corner of the picture was dragged out to enlarge it, when it reaches the specified height or width (whichever comes first) it stops. Effectively I’m making sure the picture always fills the required space on the PPT slide as best it can.
The specified sizes are:
Height: 438
Width: 705
Hope this makes sense, the section of code I need changing is below.
Any help with this would be much appreciated.

Code:
With Shp
        .LockAspectRatio = msoTrue
        .Width = 705
       
        sngDefaultSlideWidth = PPPres.PageSetup.SlideWidth
        sngDefaultSlideHeight = PPPres.PageSetup.SlideHeight
        .Left = (sngDefaultSlideWidth - .Width) / 2
        .Top = (sngDefaultSlideHeight - .Height) / 2
       
        .ZOrder msoSendToBack
End With
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Watch MrExcel Video

Forum statistics

Threads
1,122,816
Messages
5,598,264
Members
414,221
Latest member
MD1222

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
Top