PDA

View Full Version : [SOLVED:] Paste on current slide



magnel
08-26-2018, 12:05 PM
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

John Wilson
08-26-2018, 12:23 PM
You could try this:


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

magnel
08-26-2018, 12:53 PM
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

John Wilson
08-26-2018, 01:20 PM
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.

magnel
08-26-2018, 06:12 PM
The file1.pptx is placed on my office server. Will it still work if its on a server path.

John Wilson
08-26-2018, 11:59 PM
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.

magnel
08-27-2018, 08:00 AM
Wow, it worked for the file on the server.

Thank you so very much John, I was struggling on it for so long.