I need to automate the opening and saving of internet
websites. I was wondering if there was an Internet
Explorer library that I could use from VB to access things
in the browser. and if not, how can I possibly do this?
Thanks a lot in advance
Farsad
What does IE have that you want, that the WebBrowser control
can not supply?
LFS
I'd appreciate any help!!
I've been looking into this for a LONG time
>.
>
Like you , I have to go searching for this info on MSDN or wherever.
I found something to get you started, but for unattended execution
(if thats what you wanted) you are going to have to dig deeper.
http://msdn.microsoft.com/workshop/browser/mshtml/reference/constants/saveas.asp
That link brings you to the SaveAs command of the ExecWB method. There
is a whole list of commands available which I did not check out. Under that
list is the MSDN Web Browser documentation, which I also have not gone through,
but you may, as you have time....
In a new project, add the Microsoft Internet Controls from the Project>Components
menu and give the form a WebBrowser, and 2 buttons, then paste in this code:
Option Explicit
Const FileName = "D:\temp\test.mht"
Private Sub Command1_Click()
WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER, FileName
WebBrowser1.Navigate "About:<HTML>PAGE CLEARED</HTML>"
End Sub
Private Sub Command2_Click()
WebBrowser1.Navigate2 FileName
End Sub
Private Sub Form_Load()
Command1.Caption = "Save"
Command2.Caption = "Open"
Show
Refresh
WebBrowser1.Navigate2 "www.google.com"
End Sub
When the form loads, the webbowser shows Google.com (your connection must
be active) When you hit the save button you will be prompted for the file name.
YOU MUST ALSO SELECT THE PROPER FILE TYPE from that dialog box.
Select the file type "Web Archive, Single File (*.mht) from that box and navigate
to and enter the filename listed in the code. (D:\temp\test.mht) Change it in the
code to work on your system if you must. Normally you might put up your own
File Save dialog box, but I saw no way to select the proper file type from my
quick glance over the documentation. Likewise when it is time to view a file
you could filter the .mht files in a File Open dialog box. But for the demo I
made the filename a constant and you have to use that value to save the file
if you want the Open button to work....
LFS