none
Visual Basic with PowerPoint 2010, Macro for copying a NON-LINKED picture to the clipboard and setting a Shape fill to the clipboard contents. RRS feed

  • Question

  • Using PowerPoint 2010, you can manually Insert a picture (thePict), with the Insert option, onto a slide that does not link the picture to the file.  If you create a Shape (theShape), rectangle for this example, then right-click on the picture and select copy, which copies it to the clipboard, and then you can right click on the shape and select Format Shape and set the fill to the contents of the clipboard. I am able to set a variable to represent the picture in Visual basic, copy the picture to the clipboard, but I can't seem to find any answers to set the fill of the shape to the clipboard contents.  If 2010 still had Macro Recorder, I wouldn't need help.  I just can't understand why I can't find code to automate something with Visual Basic that can be done manually.  I thought that was one of the benefits of macros.  Please don't respond with linking the picture to the file!  I don't want any files linked to my presentation.

    Thank you for any help in this matter,

    senseimiller


    senseimiller

    Saturday, June 17, 2017 4:47 PM

All replies

  • I have an Inserted picture on my Slide Master. I manually copied the picture to the clipboard.  I have a Rectangle shape that I manually set the fill to the contents of the Clipboard (the picture).  I want to programmatically (VBA) set the fill of the Rectangle shape to the picture or the fill of the Rectangle shape (whichever is possible).  I have 68 pictures that I need to use in my presentation as inserted pictures to make the presentation not dependent on Linked Files. PowerPoint 2010 does not include Macro recording, so that it not an option!. None of my research has answered this question.  Any help would be greatly appreciate.

    Thanks in advance,

    Rich

    Monday, June 12, 2017 11:32 PM
  • Hi Rich,

    Based on your description, your problem need to be resolved by code, this is forum discuss questions and feedback for Microsoft Excel features, about code problem I'll move your question to the MSDN forum for Excel

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,
    Emi Zhang
    TechNet Community Support

    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, June 15, 2017 2:55 AM
  • I have an Inserted picture on my Slide Master (Inserted, not Linked). I manually copied the picture to the clipboard.  I have a Rectangle shape that I manually set the fill to the contents of the Clipboard (the picture).  I want to programmatically (VBA) set the fill of the Rectangle shape to the picture or the fill of the Rectangle shape (whichever is possible).  I have 68 pictures that I need to use in my presentation as inserted pictures to make the presentation not dependent on Linked Files. PowerPoint 2010 does not include Macro recording, so that it not an option!. None of my research has answered this question.  Any help would be greatly appreciate.

    Thanks in advance,

    Rich


    senseimiller

    Thursday, June 15, 2017 7:59 PM
  • Hi senseimiller,

    According to FillFormat.UserPicture, I think we need the picture path to fill the Rectangle shape. For getting a picture path, I suggest you save the picture to a temporary path and then you could use the path to fill the rectangle shape. You could use Shape.Export for saving the picture. Here is the example

    Sub TEST()
    Dim mst As Master
    Set mst = Application.ActivePresentation.SlideMaster
    Dim shp As Shape
    Set shp = mst.Shapes(1)
    Dim path As String
    path = "C:\Users\Desktop\Temp.jpg"
    Call shp.Export(path, ppShapeFormatJPG) 'save the picture to desktop
    With Application.ActivePresentation.Slides(1).Shapes(1)
        .Fill.UserPicture path  'fill the rectangle shape
    End With
    Kill path 'delete the picture
    End Sub

    Best Regards,

    Terry

    Friday, June 16, 2017 6:47 AM
  • I think you missed the point.  I don't want to depend on linked files!

    senseimiller

    Saturday, June 17, 2017 4:03 AM
  • Hi senseimiller,

    you had mentioned that,"I am able to set a variable to represent the picture in Visual basic, copy the picture to the clipboard, but I can't seem to find any answers to set the fill of the shape to the clipboard contents."

    I try to check the property and I find that it take parameter as string that is the path of an image.

    Set myDocument = ActivePresentation.Slides(1)
    
    With myDocument.Shapes
        .AddShape(msoShapeRectangle, 0, 0, 200, 100).Fill _
            .UserPicture "c:\windows\tiles.bmp"
        .AddShape(msoShapeRectangle, 300, 0, 200, 100).Fill _
            .UserTextured "c:\windows\tiles.bmp"
    End With
    

    because of that , we are not able to paste the image from the clipboard.

    so here its like what we can done using user interface , we cannot done the same using code.

    because Powerpoint does not expose how it pass the copied image to shape fill from the clipboard.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 19, 2017 6:32 AM
    Moderator
  • Hi senseimiller,

    I know that you want to fill the shape with picture in clipboard. I checked members of Shape Object and FillFormat, the only way I found is FillFormat.UserPicture. I think maybe office doesn't provide the method filling with picture from clipboard in Microsoft.Office.Interp.PowerPoint.dll. If we want to fill the shapes with picture, we need try to get the picture’s file path.

    Best Regards,

    Terry

    Monday, June 19, 2017 10:00 AM