Using VBA to insert/update image in PowerPoint?

ⅰ亾dé卋堺 提交于 2019-12-14 02:28:05

问题


I am making an interactive Powerpoint presentation that has previously read a text file from my local server (XAMPP) and displayed it. I'd like to now update it so that the user can hand-write their response, and it displays that on the slideshow. I have a jQuery plugin that lets someone use a stylus and it saves the 'drawing' as an image on the local server.

My question is, how can I insert the image into PowerPoint using a VBA Macro? Or since the image always will have the same file path, but will be replaced with a different image, can I somehow "Update" the image on the slide? Sorry if it's confusing.

This is the VBA I tried:

Sub insert()
    Dim oPic As Shape
    Set oPic = ActivePresentation.Slides(1).Shapes.AddPicture("http://localhost/image.png", False, True, 0, 0, -1, -1)
End Sub

I could also get the path of the image on the computer, not the server.

When I run the macro, I get a "file not found" error. Does anyone know what's wrong?

Thanks!

PS: If anyone's interested, the plugin is called Signature Pad.


回答1:


Looks like I can insert an image if it's in the exact same folder:

Sub insert()
    Dim oPic As Shape
    Set oPic = ActivePresentation.Slides(1).Shapes.AddPicture("image.png", False, True, 0, 0, -1, -1)
End Sub

This works, but if anyone knows how to go into another folder, please let me know. If I try folder/image.png or /folder/image.png as the file path, it doesn't work.




回答2:


It doesn't need to be in the exact same folder, but you do need to use Mac-style paths:

#If Mac Then
    imagePath = (MacScript("get path to startup disk as string") & "Users:name:Desktop:SomeFolder:My_Picture.png")
#Else
    imagePath = "C:\path\to\My_Picture.png"
#End If

activeSlide.Shapes.AddPicture(imagePath, False, True, 10, 10)

Hope that helps.



来源:https://stackoverflow.com/questions/15766931/using-vba-to-insert-update-image-in-powerpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!