Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a little help parsing a (physical) HTML file

Status
Not open for further replies.

MakeItSo

Programmer
Oct 21, 2003
3,316
DE
Hi friends,

I am trying to parse through a locally stored (i.e. physical) HTML document using Microsoft HTML Object library.

This is what I have so far:
Code:
Dim myDoc as HTMLDocument, lnk as HTMLAnchorElement, img as HTMLImg

...
set myDoc=new HTMLDocument
[red]myDoc.Open DaPath2MyDoc[/red]

For Each lnk In myDoc.anchors
'.... do something
Next lnk

For Each img in MyDoc.Images
'...and so forth

Now the red part is the one bugging me: the file won't load into the variable. The value of myDoc is "about:blank", not the file.
What am I doing wrong?

Thanks for any help!

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Incredible... Finally found the solution in the codeguru archives!

Solution: you need TWO objects:
Code:
Dim myDoc As HTMLDocument, [b]objMSHTML As HTMLDocument[/b]

Set objMSHTML = New MSHTML.HTMLDocument
Set myDoc = objMSHTML.createDocumentFromUrl(DaPath2MyDoc, vbNullString)[/b]

While myDoc.readyState <> "complete"
    DoEvents
Wend

For Each lnk In myDoc.links
'.... do something
Next lnk
The trick is to create an HTML Object first and then "load" the HTML into the second object by creating it using the first one...

Microsoft and logic - two things that not always go together...
[tongue]


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top