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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create HTMLDocument object from string 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I seem to be going round in circles trying to find the answer, so I hope you can help.

I have a string which is HTML , I want to create an HTMLDocument object so I can parse the elements but I just can't work out how to do it.

I have
Code:
Dim HTMLDoc As HTMLDocument
Dim sBody As String
Dim MyBrowser As InternetExplorer


sBody = DLookup("HTMLBody", "Email", "MailID=1")

Set MyBrowser = New InternetExplorer

MyBrowser.HTMLBody = sBody

HTMLDoc = MyBrowser.Document

But it errors , i've tried just setting the HTMLDoc = the string but that errors, I've tried WebBrowser.DocumentText = string, but that errors (I think that only works in C#).

I've tried MyBrowser.document = string but that errors?

I just can't seem to work out the correct syntax so your help is appreciated.

Cheers,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Here are some code notes. This will run in VBA as it stands.

Code:
Dim HTMLDoc As Object
Dim sBody As String
Dim MyBrowser As New InternetExplorer

sBody = "<HTML><Body>mail</HTML></Body>"

MyBrowser.Navigate "about:blank"
MyBrowser.Visible = True
MyBrowser.Document.Write (sBody)

 
Thanks Remou,

I tried write & writeln which I found when googling, but that was against the HTMLDocument object and that errored too.

It seemed all I could find was .NET & C# solutions!

I really appreciate your help.

Cheers,
1DMF.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Glad it worked for you. I think the real secret is navigating to about:blank because the document object does not exist until you do.

 
Yeah i guess so , though it does seem in .NET & C# you don't need to do that you can just set the HTMLDocument object's body/documenttext

I did try to use a 'new' constructor against the HTMLDocument object thinking it needed to have an instance before it could be manipulated, but that threw a really weird error!

oh well got there in the end with your help :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top