Link to home
Create AccountLog in
Avatar of apiraner

asked on

Run-time error 91during Internet Explorer .Document reference from VBA

  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:
  Option Explicit
  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()
      With goIe
         .Visible = True
      End With
     ' user clicks a button to call mdlOther.my_func
     main = 1
  End Function

Option Explicit
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.
       mdlIe.Navigate ("someurl/some.asp")
       'Select the correct project
       Set goIeDoc = goIe.Document
       sTitle = goIeDoc.Title 'works just fine.
       cframes = goIeDoc.LastChild '<--- ERROR
       'cframes = goIeDoc.getElementsByName("_TopMenu") '<--- same ERROR
   End Function

   '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
       End If
   End Sub
Public Sub Navigate(loc As String)
       ' Navigate to loc
        Call goIe.Navigate(loc)
        Call LoadPage
        End Sub
Public Sub LoadPage()
   Do While goIe.Busy Or goIe.ReadyState <> READYSTATE_COMPLETE
End Sub

I am stumped.  Thanks in advance for the help...
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Forced accept.

EE Admin