What's wrong with my InternetExplorer _DocumentComplete(...) events?

C

Craig in NJ

I apologize for what may be a stupid question, but ...

I've gotten InternetExplorer to work well within my VBA application
except for events like _DocumentComplete. How do I get the events to
work correctly? Below is an abbreviated version of what I did.

Thanks (in advance),

Craig in NJ
===========

My VBA project has enabled Tools->References -> "Microsoft Internet
Controls" (shdocwv.dll)

My VBA project has a form called WebBrowserForm with a WebBrowser
control on it. There is no code within the Form's code section.

My VBA project has a Class Module called IEwindowClass which contains
only the following code:

Public WithEvents IEwindow As shdocvw.InternetExplorer

Private Sub Class_Initialize()
Set IEwindow = New shdocvw.InternetExplorer
End Sub

Private Sub Class_Terminate()
Set IEwindow = Nothing
End Sub

Private Sub IEwindow_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
If (pDisp Is IEwindow) Then
Debug.Print "IEwindow document is ready for use"
' Note: When I tried using IEwindow.Object during some other
debugging
' I got spontaneous errors referring to object expected or
something,
' Getting rid of the .Object suffix seemed to fix the errors.
' At that moment pDisp and IEwindow both had values I could check
' in my immediate window, and (pDisp Is IEwindow) was True,
' but the Debug.Print message never appeared in my debugging
window
' (immediate window), so it seems like the event isn't working.
End If
End Sub

My VBA project also has another module called ExternalDataAccess which
contains the meat of my application, most significantly:

Option Explicit
Public IEwindow As shdocvw.InternetExplorer

Sub InitializeIEwindow()
Set IEwindowClassObject = New IEwindowClass
Set IEwindowClassObject.IEwindow =
CreateObject("InternetExplorer.Application")

' Note: The next line tries to make the local IEwindow object in this
module the
' same as the one in the IEwindowClassObject module. Originally I
had no
' class module and Set the new InternetExplorer object in this
module.
' When I moved that Set New to the above class module, it broke my
ability
' to use IEwindow in this module until I added the below Set.
' (I hope I did that right.)
Set IEwindow = IEwindowClassObject.IEwindow

IEwindow.Navigate ("about:blank")
IEwindow.Visible = True
End Sub

The rest of the ExternalDataAccess module has lots of subroutines and
functions that do things like IEwindow.Navigate( . . . ).
 

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