PDA

Click to See Complete Forum and Search --> : - RESOLVED - How to add picture from web to Word doc


anti_you
Oct 23rd, 2003, 05:49 PM
Is it possible to get Word VBA to insert a picture from a web page? I've tried the following using AddPicture method:

ActiveDocument.Shapes.AddPicture Anchor:=Selection.Range, FileName:= _
"http://www.google.ca/intl/en_ca/images/logo.gif", _
LinkToFile:=False, SaveWithDocument:=True

(as a test, loading the Google logo)
The above code is as generated by Macro record -which it gladly accepts as a valid filename.

When the macro is run however, it returns a 'Run-time error 5152 -This is not a valid filename.'
Yet if I use the Word menus: Insert, Picture, From File and enter a web addressed picture in the Filename box it finds and loads it into the Word doc without a problem. What gives? Is there another method for doing this?

Thanks.

WorkHorse
Oct 23rd, 2003, 07:21 PM
I'm not sure why that doesn't work, but this should:

With Dialogs(wdDialogInsertPicture)
.Name = "http://www.google.ca/intl/en_ca/images/logo.gif"
.LinkToFile = False
.New = False
.FloatOverText = False
.Execute
End With:)

anti_you
Oct 24th, 2003, 12:24 AM
Thanks muchly WorkHorse!:bigyello:
That did the trick!