Hi everyone,
I am trying to write a simple bit of code in order to copy-and-paste a grouped image (SmartArt + shape) into a specific slide of a specific ppt presentation.
The first part of the code, the one that opens the specific presentation - works fine, but the code gets stuck and the 2nd Sub at
Set myPic = pptSlide.Shapes.PasteSpecial(ppPasteMetafilePicture, msoFalse)
the debugger gives a "Run-time error '91' - Object variable or With block variable not set".
Here's the entire piece of code I'd like to run
Sub Open_PowerPoint()
'Opens a PowerPoint presentation from Excel
Dim objPPT As Object, s$
s = "C:\Users\davide.calzoni\Desktop\presentation1.pptx"
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Select Case Dir(s) <> ""
Case True
objPPT.Presentations.Open s
Case False
MsgBox "Could not find file!", vbCritical, s
End Select
CopyPic_to_PPT
End Sub
Sub CopyPic_to_PPT()
Dim pptSlide As PowerPoint.Slide
Dim myPic As Object
Sheets("Sheet1").Shapes("Group 1037").Copy '<-- copy the "Picture 1" image from "IMG" worksheet
' set myPic to current pasted shape in PowerPoint
Set myPic = pptSlide.Shapes.PasteSpecial(ppPasteMetafilePicture, msoFalse)
' modify current pic setting
With myPic
.Width = 121
.Height = 51
.Left = 580
.Top = 3
End With
End Sub
Please, note: I'm a newbie learner of VBA still at very basic levels of coding skills, so apologies for any possible non-sense or absurdity in the code above.
Thank you![]()
Bookmarks