Accessing DOM from VBA

  • Thread starter hansi13 via AccessMonster.com
  • Start date
H

hansi13 via AccessMonster.com

Hi,

following problem: I have an html-file which is in fact a saved file from
outlook.
The file has an table structure, in it different tables.
I now want to access a table which is identified like this:

<table><tr><td>
<p class=MsoNormal><a href="#TABLE_1"><img alt="10 rows, 33
columns"></a></p>
</td></tr>
<tr><td><table> /* Stuff I want to extract from the following 10 rows and
33 columns */ </table></td></tr></table>...

Now I surely can try to read the whole data as string and trying to parse it
but I was wondering if and how I can access the file to read/ navigate in it
by DOM - somebody can give me a starting point?

Thanks a lot in advance.

BR,
Hansi
 
D

David H

The script below opens a new window in IE and sends text to the window as it
executes. I gave you a incomplete snipet to get you going. Use
ieWindow.GetElementById("bodyTag").innerHTML to retreive the HTML located
inside the body tags. I'm guessing that if you supply specific Id's that you
can pull the innerHTML from those tags as well.

Set appIE = CreateObject("InternetExplorer.Application")
appIE.Offline = True
appIE.AddressBar = False
appIE.Height = 200
appIE.Width = 350
appIE.MenuBar = False
appIE.StatusBar = False
appIE.Silent = True
appIE.ToolBar = False
appIE.Title = "Trailer Management and Manifest Database"
appIE.Navigate ""
Do While appIE.Busy
WScript.Sleep 100
Loop
appIE.document.Open
Set ieWindow = appIE.document
ieWindow.Write "<html><head><title>"
ieWindow.Write "Microsoft Access"
 
S

Stuart McCall

hansi13 via AccessMonster.com said:
Hi,

following problem: I have an html-file which is in fact a saved file from
outlook.
The file has an table structure, in it different tables.
I now want to access a table which is identified like this:

<table><tr><td>
<p class=MsoNormal><a href="#TABLE_1"><img alt="10 rows, 33
columns"></a></p>
</td></tr>
<tr><td><table> /* Stuff I want to extract from the following 10 rows
and
33 columns */ </table></td></tr></table>...

Now I surely can try to read the whole data as string and trying to parse
it
but I was wondering if and how I can access the file to read/ navigate in
it
by DOM - somebody can give me a starting point?

Thanks a lot in advance.

BR,
Hansi

You may be able to save yourself some work by linking to the document and
letting Access make what it will of the structure. In A2003 you would
right-click on the database window border, select 'link tables...', then in
the dialog that appears, change the 'Files of type' combo to 'HTML
Documents', select your file and see what happens. On the Link tables wizard
screen, click 'Advanced'. Here you may be able to make sense of at least the
outer table.

Worth a try...
 
H

hansi13 via AccessMonster.com

Stuart said:
[quoted text clipped - 21 lines]
BR,
Hansi

You may be able to save yourself some work by linking to the document and
letting Access make what it will of the structure. In A2003 you would
right-click on the database window border, select 'link tables...', then in
the dialog that appears, change the 'Files of type' combo to 'HTML
Documents', select your file and see what happens. On the Link tables wizard
screen, click 'Advanced'. Here you may be able to make sense of at least the
outer table.

Worth a try...

Hi Stuart, nice one but I think I try it at first with the HTML-parsing. In
case I'm getting stuck I'll come back to your solution...

Thanks,
Hansi
 
H

hansi13 via AccessMonster.com

Hey David,

thanks I think I know where I have to go. Do you have some more example about
how to work with the MSHTML-Lib - can't find s. th. on the internet, help
seems not to come with the lib (at least it doesn't show me s. th.) and if I
try to use your code it works until I try to find any element (e. g. " MsgBox
doc.getElementById("table1").innerText " results in an "object not declared"-
err.

Thanks,
Hansi
 
D

David H

That's going beyond my experience and knowledge.

Are you able to at least use the code to open the document and display it in
the IE window?
 
D

David H

I did find some information pertaining to IE 3.0 in which an object reference
had to be set to the document as in ...

Set MyDocument = [browser].Document

Don't know if it still applies, but I'd try it.
 
H

hansi13 via AccessMonster.com

David said:
That's going beyond my experience and knowledge.

Are you able to at least use the code to open the document and display it in
the IE window?
Hey David,
[quoted text clipped - 7 lines]
Thanks,
Hansi

I'm sorry, not really. The code is running without error, there is a process
in the background but the window is not displaying... I will try to find some
infos somewhere and will post it.

BR,
Hansi
 
D

David H

Oh well.



hansi13 via AccessMonster.com said:
David said:
That's going beyond my experience and knowledge.

Are you able to at least use the code to open the document and display it in
the IE window?
Hey David,
[quoted text clipped - 7 lines]
Thanks,
Hansi

I'm sorry, not really. The code is running without error, there is a process
in the background but the window is not displaying... I will try to find some
infos somewhere and will post it.

BR,
Hansi
 

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