From: Southern at Heart on
How can I end this code so that it will save the image in 'My Documents'
instead of just pasting it into the word document? It is a .gif format on
the
web, but it can be something else if it's easier.
Thanks.


> Sub Comics()
> ' Open the first webpage
> Set ie = CreateObject("InternetExplorer.Application")
> With ie
> .Visible = True
> .navigate "http://www.gocomics.com/calvinandhobbes/2010/01/16
> "
> .Top = 50
> .Left = 530
> .Height = 400
> .Width = 400
> ' Loop until the page is fully loaded
> Do Until .ReadyState = 4 And Not .Busy
> DoEvents
> Loop
> ' Determine the url for the image
> my_var = ie.document.body.innerhtml
> loc_1 = InStr(1, my_var, "feature_item>", vbTextCompare)
> loc_2 = InStr(loc_1, my_var, "//", vbTextCompare)
> loc_3 = InStr(3 + loc_2, my_var, ">", vbTextCompare)
> my_url = Trim(Mid(my_var, 2 + loc_2, loc_3 - (2 + loc_2)))
> ' Go to the image url and copy the image and paste to the activesheet
> ie.navigate my_url
> Do Until ie.ReadyState = 4 And Not ie.Busy
> DoEvents
> Loop
> ie.ExecWB 17, 2
> ie.ExecWB 12, 0
> ActiveSheet.PasteSpecial
> End With
> ie.Quit
> End Sub


From: Doug Robbins - Word MVP on
Probably ActiveWorkbook.SaveAs etc.

I assume that you are talking about Excel from the ActiveSheet

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Southern at Heart" <SouthernatHeart(a)discussions.microsoft.com> wrote in
message news:3356E8DC-B1D8-4C4E-8B0C-06EF48BDE515(a)microsoft.com...
> How can I end this code so that it will save the image in 'My Documents'
> instead of just pasting it into the word document? It is a .gif format on
> the
> web, but it can be something else if it's easier.
> Thanks.
>
>
>> Sub Comics()
>> ' Open the first webpage
>> Set ie = CreateObject("InternetExplorer.Application")
>> With ie
>> .Visible = True
>> .navigate "http://www.gocomics.com/calvinandhobbes/2010/01/16
>> "
>> .Top = 50
>> .Left = 530
>> .Height = 400
>> .Width = 400
>> ' Loop until the page is fully loaded
>> Do Until .ReadyState = 4 And Not .Busy
>> DoEvents
>> Loop
>> ' Determine the url for the image
>> my_var = ie.document.body.innerhtml
>> loc_1 = InStr(1, my_var, "feature_item>", vbTextCompare)
>> loc_2 = InStr(loc_1, my_var, "//", vbTextCompare)
>> loc_3 = InStr(3 + loc_2, my_var, ">", vbTextCompare)
>> my_url = Trim(Mid(my_var, 2 + loc_2, loc_3 - (2 + loc_2)))
>> ' Go to the image url and copy the image and paste to the activesheet
>> ie.navigate my_url
>> Do Until ie.ReadyState = 4 And Not ie.Busy
>> DoEvents
>> Loop
>> ie.ExecWB 17, 2
>> ie.ExecWB 12, 0
>> ActiveSheet.PasteSpecial
>> End With
>> ie.Quit
>> End Sub
>
>
From: Karl E. Peterson on
Southern at Heart wrote:
> How can I end this code so that it will save the image in 'My Documents'
> instead of just pasting it into the word document?

You really can't. You need to take an entirely different approach.
Well, "can't" and "need" are pretty strong. Let's say I'd *strongly*
recommend an entirely different approach. This is probably the
simplest method:

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

If you need to display status, or otherwise have finer control, that
too can come with increasing complexity of the code.

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Southern at Heart on
....I don't know if that method will work, as the image I'm wanting to save is
not a 'real' image until IE loads it.
....so what I end up with is a .gif file in the clipboard. Is there a way to
save a .gif file that's on the clipboard to a file?

From: Karl E. Peterson on
Southern at Heart wrote:
> ...I don't know if that method will work, as the image I'm wanting to save is
> not a 'real' image until IE loads it.
> ...so what I end up with is a .gif file in the clipboard. Is there a way to
> save a .gif file that's on the clipboard to a file?

Oh, ick! I really didn't look closely at the code you were using, or
the page you pointed to. I don't even see the GIF in the source for
that, either. I guess it's this, eh?

http://imgsrv.gocomics.com/dim/?fh=83fba46523c3b2f31aeb078a548010a8

Why do you say it's not a "real image" until IE loads it? Is the other
server creating it on demand? That API call will do the same thing,
essentially.

Anyway, yes, it is potentially possible to save a GIF from the
clipboard to file, but it's not a very simple process at all. I would
definitely try everything you can to find another route.

--
..NET: It's About Trust!
http://vfred.mvps.org