Using VBA to change Picture

后端 未结 10 1003
庸人自扰
庸人自扰 2020-12-10 12:41

I am trying to use VBA to automate the Change Picture function when you right click a Shape in Excel/Word/Powerpoint.

However, I am not able to find any reference, c

相关标签:
10条回答
  • 2020-12-10 12:56

    You can change the source of a picture using the UserPicture method as applied to a rectangle shape. However, you will need to resize the rectangle accordingly if you wish to maintain the picture's original aspect ratio, as the picture will take the dimensions of the rectangle.

    As an example:

     ActivePresentation.Slides(2).Shapes(shapeId).Fill.UserPicture ("C:\image.png")
    
    0 讨论(0)
  • 2020-12-10 13:04

    i use this code :

    Sub changePic(oshp As shape)
        Dim osld As Slide
        Set osld = oshp.Parent
        osld.Shapes("ltkGambar").Fill.UserPicture (ActivePresentation.Path & "\" & oshp.Name & ".png")
    End Sub
    
    0 讨论(0)
  • 2020-12-10 13:05

    I'm working in Excel and VBA. I can't overlay images because I have multiple sheets of a variable number and each sheet has the images, so the file would get huge if, say 20 sheets had all 5 images I want to animate.

    So I used a combination of these tricks listed here: 1) I inserted an RECTANGLE shape at the location and size I wanted:

    ActiveSheet.Shapes.AddShape(msoShapeRectangle, 1024#, 512#, 186#, 130#).Select
    Selection.Name = "SCOTS_WIZARD"
    With Selection.ShapeRange.Fill
      .Visible = msoTrue
      .UserPicture "G:\Users\ScotLouis\Documents\My Spreadsheets\WordFind Wizard\WordFind Wizard 1.jpg"
      .TextureTile = msoFalse
    End With
    

    2) Now to animate (change) the picture, I only need to change the Shape.Fill.UserPicture:

    ActiveSheet.Shapes("SCOTS_WIZARD").Fill.UserPicture _
        "G:\Users\ScotLouis\Documents\My Spreadsheets\WordFind Wizard\WordFind Wizard 2.jpg"
    

    So I've accomplished my goal of only having 1 picture per sheet (not 5 as in my animation) and duplicating the sheet only duplicates the active picture, so the animation continues seamlessly with the next picture.

    0 讨论(0)
  • 2020-12-10 13:12

    ![Please find attached code. First create a shape in PPT and run the code]1

    0 讨论(0)
提交回复
热议问题