vba (or other programming) for reading internet explorer webpages

R

richardconers

I have a large number of files saved as htm or html documents. These
files (saved from the web with internet explorer as the browser) each
contain zillions of hyperlinks (which I don't need) and zillions of
embedded tables and other strange formatting. Ideally, I'd like to be
able to read the infomation in the files and store the information in
Access (I am very proficient in Access VBA).

When I use Word to open the files, it takes forever for the document to
open, and even then, the information is basically unreadable because
the table configurations are incredibly screwed up. The same thing
happens when I copy from the web browser (internet explorer) and paste
into Word. I have also used getfromclipboard method, however, that
does not seem to preserve the columns, so the information is all
smashed together.

Is there any way to use VBA (without first opening the file via the
Word application) to
1) to open a web file as a web file [when i look at the
filescriptingobject in the vba help, it doesn't look like it has a file
open command)

2) use regular VBA commands such as setting range objects, collecting
information into string variables etc from this open web file ?

For example, if the web page is the only Internet Explorer file open,
can VBA "access" that window/screen? How can use (in VBA) something
like "Find" to find the data I'm looking for, and then move from column
to column reading the information?

Or what new language <sigh> do I have to learn to be able to do this
with web pages on the internet?
thank you!!!
 
E

Edward Thrashcort

Hi Richard

It took me a certain amount of blood, sweat and tears to find this out but
you can download a web page to file using this code below. However, parsing
the file into usable data might not be easy!!

Eddie

Private Declare Function URLDownloadToFile Lib "urlmon" Alias
"URLDownloadToFileA" ( _
ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFilename As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Private Function WebToFile(szURL As String, szFilename As String) As Long
Dim pCaller As Long
pCaller = 0
Dim dwReserved As Long
dwReserved = 0
Dim lpfnCB As Long
lpfnCB = 0

WebToFile = URLDownloadToFile(pCaller, szURL, szFilename, _
dwReserved, lpfnCB)
End Function


Sub testWebToFile()
Dim xRetCode As Long
Dim sURL As String
Dim sFilename As String

sURL = "http://www.topwebsite.co.uk/metatags.shtml"
sFilename = "c:\temp\metatags.htm"

xRetCode = WebToFile(sURL, sFilename)
End Sub
 

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