PowerPoint 2007 VBA Picture from URL Workaround
Dim pic As IPictureDispIn order to get an image from the web into a PowerPoint 2007 presentation, one must first save the image locally as a file, then reference the file. The Module code is adapted from Workaround for Powerpoint 2007 VBA AddPicture web image problem. The URLs referenced below are sample images that I created for a good image and an image not available error. Replace them with your own images.
'Load good image
Set pic = stdole.StdFunctions.LoadPicture("http://tinyurl.com/d85tgr")
Image1.Picture = pic
In a Module, enter the following:
Option ExplicitIn the presentation code, for example, use the following code to load the good image from the default file to an Image control:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Public Function DownloadFile(sSourceURL As String, _
sLocalFile As String) As Boolean
DownloadFile = URLDownloadToFile(0&, _
sSourceURL, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function
Sub ImportPictureFromWeb(Optional SourceFile As String _
, Optional DestinationFile As String)
Dim sSourceURL As String
Dim sLocalFile As String
Dim x As Variant
If Len(SourceFile) > 0 Then
sSourceURL = SourceFile
Else
'Load image not available error image
sSourceURL = "http://tinyurl.com/d8home"
End If
If Len(DestinationFile) > 0 Then
sLocalFile = DestinationFile
Else
'Default file
sLocalFile = "C:\PowerPointImage.gif"
End If
x = DownloadFile(sSourceURL, sLocalFile)
End Sub
Dim pic As IPictureDisp
Module1.ImportPictureFromWeb ("http://tinyurl.com/d85tgr")
Set pic = stdole.StdFunctions.LoadPicture("C:\PowerPointImage.gif")
Image1.Picture = pic





Stumble It!
