PDA

View Full Version : Add a picture from the web using vba



naeblis
06-03-2007, 07:56 PM
When I run this code to add a picture in office 2007, I cant get excel vba to add a picture from the web. If it is a local picture this code works fine. It also seems to work fine on prior versions of office. Anyone run into this before?

Dim p As Object
Set p = ActiveSheet.Pictures.Insert("F:\myimage.jpg")

Oorang
06-03-2007, 09:30 PM
Hmm you might just need to fully declare your url. This works fine for me:Sub test()
Dim p As Excel.Picture
Set p = ActiveSheet.Pictures.Insert(_
"http://www.live.com/live/1.900.8.051/img/wl_jewel.gif")
End Sub
(Note you can dim as object too if you like, but there is no real need to do latebinding in this instance.)

naeblis
06-04-2007, 08:22 AM
Just out of curiosity, what version of office/excel are you trying this on? Your code and the one I posted earlier will work on anything but my laptop, which happens to be running Office 2007. I have tried using the macro recorder to see what office 2007 provides for code, but it does not provide any code when adding or changing images...

Oorang
06-04-2007, 09:14 AM
Works on 97 & 2003.

naeblis
06-04-2007, 01:05 PM
Anyone try it in office 2007, or know why it won't work in office 2007. Im running into a wall trying to figure out what I have to do. At this point I added a web browser control to show the picture. This does not seem like an efficient way to do it...