Powerpoint 2007 VBA AddPicture web image problem

G

Guest

(warning, VBA newbie....)

I have a macro which has been working fine when run in PP 2003 but is not
working in PP 2007. I'm trying to insert an image onto a slide, the image is
on a web server so I have something similar to the following code:

ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="http://webserverhost/images/image1.gif",
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=323, Top:=233,
Width:=75, Height:=75).Select

In PP 2003, it works fine, the web image correctly gets displayed on the
slide.
In PP 2007, I get a 'Error -2147024809: The specified file wasn't found'

If I 'manually' insert the pic in a slide, by choosing Insert->Picture and
then specify 'http://webserverhost/images/image1.gif' as the filename, the
image shows up in the slide as it should. In otherwords, if i don't run the
macro and do it by hand in PP, it works.

I'm not sure what is going on. Is there something new in PP 2007 that is
preventing images from a web server (which in my case happens to be on the
local machine, so it's an internal web site) being added to a slide?

Thanks in advance for any help!

-BP
 
S

Steve Rindsberg

Replied to elsewhere.

Short version: seems you've found a bug (or something that's broken by design).
It's gone up the ladder to MS. With luck we'll hear back which it is, but I can't promise when or even if
that'll happen.
 
Joined
Jun 13, 2008
Messages
1
Reaction score
0
Workaround for Powerpoint 2007 VBA AddPicture web image problem

I know this is an old thread, however, I was having the same problem and have come up with a workaround.

PP2007 allowed me to use VBA to insert a picture from a drive, but not from the web.

Using the URLDownloadToFile API I wrote a function to save the image. I then import the saved image to PowerPoint through VBA.

HTH,
Kevin



'-=* CODE START *=-
Option Explicit
'Declare API Function
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



'Call API Function

Public Function DownloadFile(sSourceURL As String, _

sLocalFile As String) As Boolean

'Download the file. BINDF_GETNEWESTVERSION forces

'the API to download from the specified source.

'Passing 0& as dwReserved causes the locally-cached

'copy to be downloaded, if available. If the API

'returns ERROR_SUCCESS (0), DownloadFile returns True.

DownloadFile = URLDownloadToFile(0&, _

sSourceURL, _

sLocalFile, _

BINDF_GETNEWESTVERSION, _

0&) = ERROR_SUCCESS

End Function



'Sub to call 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

sSourceURL = "http://gc.kls2.com//cgi-bin/gcmap?P...STYLE=&MAP-STYLE=topo&PATH-COLOR=red&MARKER=1"



End If



If Len(DestinationFile) > 0 Then

sLocalFile = DestinationFile

Else

sLocalFile = "F:\Maintenance Operations\MOC\MorningMeeting\map.gif"

End If

x = DownloadFile(sSourceURL, sLocalFile)

End Sub

'Test Function while passing parameters

Sub TestFunctionWithParameters()

Dim x As Variant

Dim strURL As String

Dim strFile As String



strURL = "http://gc.kls2.com//cgi-bin/gcmap?P...STYLE=&MAP-STYLE=topo&PATH-COLOR=red&MARKER=1"

strFile = "C:\MyFile.gif"



x = ImportPictureFromWeb(strURL, strFile)

ActivePresentation.Slides(2).Shapes.AddPicture _

FileName:=strFile, _

LinkToFile:=msoTrue, _

SaveWithDocument:=msoTrue, _

Left:=0, _

Top:=115, _

Width:=720, _

Height:=360.75

End Sub



'Test Function without passing parameters

Sub TestFunctionWithoutParameters()

Dim x As Variant

Dim strFile As String



strFile = "C:\MyFile.gif"



x = ImportPictureFromWeb()

ActivePresentation.Slides(2).Shapes.AddPicture _

FileName:=URL, _

LinkToFile:=msoTrue, _

SaveWithDocument:=msoTrue, _

Left:=0, _

Top:=115, _

Width:=720, _

Height:=360.75



End Sub









> (warning, VBA newbie....)

>

> I have a macro which has been working fine when run in PP 2003 but is not

> working in PP 2007. I'm trying to insert an image onto a slide, the image is

> on a web server so I have something similar to the following code:

>

> ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="http://webserverhost/images/image1.gif",

> LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=323, Top:=233,

> Width:=75, Height:=75).Select

>

> In PP 2003, it works fine, the web image correctly gets displayed on the

> slide.

> In PP 2007, I get a 'Error -2147024809: The specified file wasn't found'

>

> If I 'manually' insert the pic in a slide, by choosing Insert->Picture and

> then specify 'http://webserverhost/images/image1.gif' as the filename, the

> image shows up in the slide as it should. In otherwords, if i don't run the

> macro and do it by hand in PP, it works.

>

> I'm not sure what is going on. Is there something new in PP 2007 that is

> preventing images from a web server (which in my case happens to be on the

> local machine, so it's an internal web site) being added to a slide?

>

> Thanks in advance for any help!

>

> -BP

>



-----------------------------------------

Steve Rindsberg, PPT MVP

PPT FAQ: www.pptfaq.com

PPTools: www.pptools.com

================================================[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top