Consulting

Results 1 to 7 of 7

Thread: Paste on current slide

  1. #1

    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

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    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

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    The file1.pptx is placed on my office server. Will it still work if its on a server path.

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    Wow, it worked for the file on the server.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •