-
Paste on current slide
Hello,
I am trying to copy a group of shapes from a slide in another PPT file and paste on the slide in the current active PPT file.
Following is the code i am working on, it copies the grouped shapes but does not paste.
Sub copy_group8()
Dim objPres As Presentation
Set objPres = Presentations.Open("\\Desktop\file1.pptx")
Dim ppshape As Object
objPres.Slides.Item(1).Shapes("Group 8").Copy
Set ppshape = activewindow.Selection.SlideRange.Shapes.Paste
objPres.Close
End Sub
Please can I get some help correcting the above code to paste the copied shapes on the current slide.
Thanks
-
You could try this:
Code:
Sub copy_group8()
Dim objPres As Presentation
Dim osld As Slide
Dim presPath As String
strPath = Environ("USERPROFILE") & "\Desktop\file1.pptx" ' USE "\\Desktop\file1.pptx" if it works for you
'ref current slide
Set osld = ActiveWindow.Selection.SlideRange(1)
Set objPres = Presentations.Open(FileName:=strPath, WithWindow:=msoFalse)
Dim ppshape As ShapeRange
objPres.Slides.Item(1).Shapes("Group 8").Copy
Set ppshape = osld.Shapes.Paste
objPres.Close
End Sub
-
Thanks John for helping.
while using the above code got an error on this line.
Set objPres = Presentations.Open(FileName:=strPath, WithWindow:=msoFalse)
saying, Method 'Open' of object 'Presentations' failed
-
That is likely to be because you do not have a file named file1.pptx on your desktop. Your code with \\Desktop\file1.pptx doesn't work for me but my code does.
-
The file1.pptx is placed on my office server. Will it still work if its on a server path.
-
It should but you would need to use the path to the file on the server. My code is for a file on the local desktop.
-
Wow, it worked for the file on the server.
Thank you so very much John, I was struggling on it for so long.