+ Reply to Thread
Results 1 to 9 of 9

Pasting image to powerpoint slide

  1. #1
    Registered User
    Join Date
    01-21-2019
    Location
    Vilnius, Lithuania
    MS-Off Ver
    365
    Posts
    3

    Pasting image to powerpoint slide

    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

    Please Login or Register  to view this content.
    Set myPic = pptSlide.Shapes.PasteSpecial(ppPasteMetafilePicture, msoFalse)
    Please Login or Register  to view this content.
    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

    Please Login or Register  to view this content.
    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 Login or Register  to view this content.
    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

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Pasting image to powerpoint slide

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Pasting image to powerpoint slide

    essentially all you didn't do was set which slide of the powerpoint you are pasting to
    as you called a sub...you lose all variables set in first module

    so unless you want to be passing it around...just join them together to be like
    Please Login or Register  to view this content.
    ps I'm assuming you did early binding of the MS power point reference

  4. #4
    Registered User
    Join Date
    01-21-2019
    Location
    Vilnius, Lithuania
    MS-Off Ver
    365
    Posts
    3

    Re: Pasting image to powerpoint slide

    Hi Humdingaling,

    thank you for your quick answer. Yes, I made early binding of MS power point reference. I've ticked the Microsoft PowerPoint 16.0 Object Library in the References panel.

    I see the logics of my mistake, I removed my code with the one you wrote, however apparently there's still something wrong.
    When I run the macro, I get a Run-time error 429 - ActiveX component can't create object. The debugger shows the problem is here:

    Please Login or Register  to view this content.
    Any suggestion on this?

    Thank you for your time and attention

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Pasting image to powerpoint slide

    How about this one.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    01-21-2019
    Location
    Vilnius, Lithuania
    MS-Off Ver
    365
    Posts
    3

    Re: Pasting image to powerpoint slide

    Hi Bakerman2,

    Thank you for your answer.
    Your code worked smoothly, kudos.

    Have a great day!

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Pasting image to powerpoint slide

    Glad to help and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Pasting image to powerpoint slide

    oops forgot to change that line back

    thanks for cleaning up bakerman

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Pasting image to powerpoint slide

    No worries.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Add new slide to Powerpoint
    By rpinxt in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-08-2017, 09:30 AM
  2. [SOLVED] Add slide in Powerpoint via Excel
    By benishiryo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2015, 06:24 AM
  3. Replies: 6
    Last Post: 08-18-2015, 06:39 AM
  4. importing PDF into powerpoint slide
    By OliverBrain in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2015, 10:25 AM
  5. Make a powerpoint slide that scrolls down a large image.
    By 111StepsAhead in forum PowerPoint Formatting & General
    Replies: 2
    Last Post: 03-18-2013, 03:16 AM
  6. [SOLVED] Copying worksheetname to powerpoint slide
    By irfanparbatani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2012, 01:04 AM
  7. [SOLVED] pasting excel data in a powerpoint slide
    By James in forum Excel General
    Replies: 4
    Last Post: 01-28-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1