Adding pictures from the Web to a Powerpoint slide in VBA (MacOS)

ⅰ亾dé卋堺 提交于 2021-02-08 05:43:44

问题


I'm comfortably using VBA to iterate through a list of content in an Excel spreadsheet and creating slides in a separate Powerpoint file. That bit works.

However I can't seem to add pictures to the Powerpoint presentation. I've tried:

  • Using Shapes.AddPicture with an URL to the image. A few mention this should work; apparently it broke in some Office version (see http://www.pcreview.co.uk/forums/powerpoint-2007-vba-addpicture-web-image-problem-t3171074.html);
  • Using Shapes.AddPicture with the path to a file. This should work, but:

Dim pic
Set pic = activeSlide.Shapes.AddPicture("/Users/Pedro/My_Picture.png", False, True, 10, 10)

...fails with a Runtime Error 5 (invalid procedure call or argument). Please note I'm on Mac OS X, Office 2011.

I've also tried setting the Fill of an object via UserPicture() to no avail.

Thanks in advance for any help on this!


回答1:


This works on Windows versions of PPT but fails in Mac 2011:

Sub thing()
Dim oPic As Shape
Set oPic = ActivePresentation.Slides(1).Shapes.AddPicture("http://www.somesite.xxx/directory/filename.jpg", False, True, 0, 0, -1, -1)
End Sub

Quite a few things that should work (and do in the Win versions) fail in Mac PPT, unfortunately.

The last two -1 parameters tell PPT to bring the picture in at "natural" size ... ie, whatever size it'd normally insert the image if you did it manually; this avoids distorting the image.




回答2:


The issue is the path style you are using. The following will work:

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

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


来源:https://stackoverflow.com/questions/15191055/adding-pictures-from-the-web-to-a-powerpoint-slide-in-vba-macos

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