Run-time error 91during Internet Explorer .Document reference from VBA
Posted on 2007-10-03
I need to write an app to get data in and out of tools with a web front end. The pages are kind of complicated, and run java, asp... I tried perl::LWP but got stumped by embeded java scritps, and so decided to use IE, and write a vb script to control it (hope that's the right way to go). I am using VBA out of excel 2003 Pro, sp2.
I am getting a Run-time error 91 when i try to execute any methods out of my .Document object, but I get the correct answer when I reference the .Document.Title object. .Document.LastChild also errors out... The code is below, in the order it gets called:
Public goIe As InternetExplorer 'Ie is the name of my global object for browser - EMPTY at this time!!!
Public goIeDoc As Object
Public Function main()
.Visible = True
' user clicks a button to call mdlOther.my_func
main = 1
Dim cframes As Object
Public Function my_func()
' go to some websites...
mdlIe.Navigate ("someurl") ' snipped - it goes there just fine, can see on screen.
'run an asp script - snipped -runs just fine, again can see on screen.
'Select the correct project
Set goIeDoc = goIe.Document
sTitle = goIeDoc.Title 'works just fine.
cframes = goIeDoc.LastChild '<--- ERROR
'cframes = goIeDoc.getElementsByName("_TopMenu") '<--- same ERROR
'credit goes to a guy from some web site I found this on :)
Public Sub GetIE()
'Makes sure goIe is created prior to being used.
If goIe Is Nothing Then
Set goIe = New InternetExplorer
goIe.Visible = False
'I don't know why this causes problems, can supress the warn manually for now...
'goIe.Silent = True
Public Sub Navigate(loc As String)
' Navigate to loc
Public Sub LoadPage()
Do While goIe.Busy Or goIe.ReadyState <> READYSTATE_COMPLETE
I am stumped. Thanks in advance for the help...