Hello. I'm trying to write VBA code (in Excel) to browse web pages and save them to files.
I already have VBA code to automate Internet Explorer, navigate to web pages, and extract the text of the pages. But now I want to save the entire page, including images. In other words, I'd like to do the equivalent of manually printing the web page to PDF, saving it as an MHTML file, saving it as "Web page, Complete" (with the images in a separate folder), or possibly saving the whole web page as one image file.
1. Initiating a print job in IE, having made "Print to PDF" the default. I've tried various variations on this statement:
IE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
The problem is that it opens a Print dialog box followed by a Save File dialog box, and the only way I can find to interact with these boxes is to use SendKeys. But that's unrelaible. I don't know how long to wait for the dialog box to appear before sending the keys.
2. Creating an MHTML file using CDO, with this statement:
cdoMsg.CreateMHTMLBody url, cdoSuppressNone
This works, but it produces a very poorly rendered version of the web page.
Can you suggest any other options, please? I'd be open to using method #1 above, if I could detect when the dialog boxes are ready to receive keys with SendKeys. Alternatively, perhaps I should use a different technology. I'm only really familiar with VBA, but I understand that there are VBA wrappers available for WebKit and Selenium. Perhaps I could use one of those, if it's not going to be too complicated.