简体   繁体   中英

Pasting cell range from MS Excel into MS PowerPoint using VBA

I'm using below code to paste cell range in Excel as image into PowerPoint.

xlApp.Worksheets(5).Range("B2:D9").Copy
Set shp1 = ActivePresentation.Slides(4).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)

With shp1
' Set position:
.Left = 22
.Top = 95
' Set size:
.Height = 250
.Width = 280
End With

But image is not being pasted as of defined size, ie height 250 and width 280. As per my understanding, it considers aspect ratio of the image while pasting and does not distort it. But I don't want that. I just want it to cover the entire area I want on PowerPoint.

You need to switch off aspectratio parameter before you set widht and height:

With shp1
' Set position:
.Left = 22
.Top = 95
' Set size:
.LockAspectRatio = msoFalse
.Height = 250
.Width = 280
End With

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM