PC Review


Reply
Thread Tools Rate Thread

Powerpoint 2007 VBA AddPicture web image problem

 
 
=?Utf-8?B?QlA=?=
Guest
Posts: n/a
 
      23rd Jul 2007
(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
 
Reply With Quote
 
 
 
 
Steve Rindsberg
Guest
Posts: n/a
 
      23rd Jul 2007
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.


In article <71BC2140-A690-4ADB-B0A1-(E-Mail Removed)>, Bp wrote:
> (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
================================================


 
Reply With Quote
 
New Member
Join Date: Jun 2008
Posts: 1
 
      13th Jun 2008
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?PATH=PGUA,LERT,KDOV,ETAR&RANGE=&PATH-COLOR=red&PATH-UNITS=nm&SPEED-GROUND=&SPEED-UNITS=kts&MARKER=1&RANGE-STYLE=outline&RANGE-COLOR=navy&MAP-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?PATH=PGUA,LERT,KDOV,ETAR&RANGE=&PATH-COLOR=red&PATH-UNITS=nm&SPEED-GROUND=&SPEED-UNITS=kts&MARKER=1&RANGE-STYLE=outline&RANGE-COLOR=navy&MAP-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]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shapes.AddPicture(...) - different behavior in Powerpoint 03 vs. 2 Wolf7 Microsoft Powerpoint 3 3rd May 2010 06:35 PM
Exporting Image in PowerPoint 2007 Susie Microsoft Powerpoint 0 22nd Nov 2008 02:54 AM
Excel 2007 .AddPicture: Can it use a URL as a source? es330td@gmail.com Microsoft Excel Programming 1 5th Mar 2008 12:07 AM
Excel 2007 AddPicture help needed es330td@gmail.com Microsoft Excel Programming 1 22nd Feb 2008 05:28 PM
Excel 2007 Prohibits Shapes.AddPicture from URL? =?Utf-8?B?TGF6emFyb25p?= Microsoft Excel Programming 4 8th Jun 2007 10:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:12 AM.