VBA - Saving a web page locally.

BratFire

Board Regular
Joined
Aug 2, 2005
Messages
99
Code:
Dim IE As Object 
Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 
IE.navigate "http://www.MrExcel.com" 
Do 
If IE.readyState = 4 Then 
IE.Visible = False 
Exit Do 
Else 
DoEvents 
End If 
Loop 
MsgBox "Done" 
IE.Visible = True
Using the above code to open a web page, is there a way to 'save as' the web page to a local drive using VB code?
 
Right_Click said:
This code will bring up the SaveAs dialog but that still does not automate the process. I'll work on an API solution because this may come in handy in the future.
I hate to say it, but a sendkeys workaround may be useful here. (Ouch, that kinda hurt. :oops: )

I personally do not like the Internet Controls library, I don't think it's developed enough. A [better] solution for this would be nice, yes. :)
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Yes, although I generally do not recommend it. Look at it in the Help files. When you bring up your IE page after loading, might be something like ..

Code:
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%f"
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%a"
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "filename here"
Application.Wait (Now + TimeValue("0:00:02"))
Application.SendKeys "%s"

This is generally a bad way to go, each computer is different and it will error when stepping through which makes testing difficult.
 
Upvote 0
I get it. the "%f" is like an Alt-F. Would this work even if IE was not visible but yet still has the focus?
 
Upvote 0
No BratFire. Sendkeys is even worse than what I gave you. FireFyter must not have downloaded the examples. The API functions are sending messages directly to the controls which is going to produce more reliable results than simulating keystroke or mouseclicks. Like he said, sendkeys is not usually a very dependable solution. After some more research I found that the automatic downloading of script, images, and other dependant files for any given web page is not intended to be easy or included in MS Inet Controls functionality because of security concerns. I have only found one example on the net and that was using using C++ code. I don't know C but could read it well enough to see that it was pretty much a hack using a windows hook on the dialog in IE. That is what I may attempt to work on if I get around to it. With broadband becoming more affordable and more available, web page caching programs are not as popular as they used to be but there are still a handful of them out there. What are you doing by the way? Why do you need to download the entire contents of a web page. Not being nosey; just maybe your goal can be reached some other way... If I do come up with a page downloader, it will be an ActiveX.exe server. Can you use this? If so, I'll post it if and when I develop it...

Would this work even if IE was not visible but yet still has the focus?

An invisible window cannot recieve focus...

Tom
 
Upvote 0
... If I do come up with a page downloader, it will be an ActiveX.exe server. Can you use this? If so, I'll post it if and when I develop it...

That's OK. I was never going to consider the sendkeys method, just asking a couple of side questions there.

What I needed the 'save as' automation for is pretty much a one-shot deal calling in hundreds of small individual web pages. The download you supplied to me works great. I added some code to read in several links (or URLs) from several index html pages into column A and and fired the execution button. Got what I needed in less than 30 minutes with what would have taken me much longer. Than you again.

Just for reference, could you explain the activeX.exe server?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top