Pasting a picture programmatically

S

Southern at Heart

Word 2003; I need to paste a picture into the body of the doc. Problem is,
the picture is not on my pc, it's on the web. I have the URL already
calculated by my code and assigned as a string (strURL) So the web address
of the picture is strURL. Can someone please tell me how to 'get' the
picture and then paste it into the document?
thanks, SouthernAtHeart
(I hope this isn't double posted, my machine locked up and I had to start a
new post)
 
K

Karl E. Peterson

Southern at Heart brought next idea :
Word 2003; I need to paste a picture into the body of the doc. Problem is,
the picture is not on my pc, it's on the web. I have the URL already
calculated by my code and assigned as a string (strURL) So the web address
of the picture is strURL. Can someone please tell me how to 'get' the
picture and then paste it into the document?

Okay, so, to answer this, I fired up the Macro Recorder, and offered
the name "PasteImageFromUrl" for the new macro. I then went to
Insert-Picture-FromFile... and gave it the URL. I pressed Enter, and
then stopped the macro recorder. Guesses where this is going? I
opened the VB IDE, navigated to the new macro, and lo and behold...

Sub PasteImageFromUrl()
'
' PasteImageFromUrl Macro
' Macro recorded 1/21/2010 by Karl E. Peterson
'
Selection.InlineShapes.AddPicture FileName:= _
"http://www.google.com/intl/en_ALL/images/logo.gif", _
LinkToFile:=False, _
SaveWithDocument:=True
End Sub

Try it! :)
 
S

Southern at Heart

GREAT! I've been working on this for days! I've learned a lot from the
macro recorder, but I didn't know word had the insert file from webpage
option!
many thanks.
 
K

Karl E. Peterson

Southern at Heart has brought this to us :
GREAT! I've been working on this for days! I've learned a lot from the
macro recorder, but I didn't know word had the insert file from webpage
option!

I never know what I don't know until I know it. <g> Doesn't take long
to try stuff like that, so I did. Voila!

Glad it helped.
 
S

Southern at Heart

I am also needing to resize this picture. I know how to record a macro
resizing a picture, but here's my problem:
I want to resize the picture to--the page width minus the right and left
margins.
So what ever the current page width is, minus the right and left margins, I
want to resize the picture to this, keeping the aspect ratio. There must be
a page property or something that tells me the page size/margins?
thanks.
 
K

Karl E. Peterson

It happens that Southern at Heart formulated :
It doesn't work!
When I run my completed code, I get the message:
'The graphics filter was unable to convert this file'
Any ideas?
the picture in this case is located at:
http://imgsrv.gocomics.com/dim/?fh=fd933fd26e764bfd5ca061710701f811&w=900.0

You'll need to use "another method" to download it, saving to a temp
file, then opening the saved temp file. Here's one way:

http://vbnet.mvps.org/code/internet/urldownloadtofilenocache.htm

If this were VB6, I'd point you instead towards the AsyncRead method of
a UserControl - http://vb.mvps.org/samples/NetGrab

Problem just got messier.
 

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