I'm writing a PB9 app which uses MS Word. The PB COM Browser generated source code to define Word IDs, classes, etc. using MSWORD9.OLB. (I need to support Word 2000, XP, 2003 and 2007. MS recommends using the oldest version of Word which will be used.)
My globals module defines:
The function which initializes an instance of Word includes:
The app is able to connect with Word, then get/set properties and call methods with no problems. Results are identical on Word 2000, XP and 2007.
But I wasn't receiving all events. This is how I rigged the event-handling class:
Startup, Quit and DocumentChange are always called when they should be. The other events are never called.
Cleverly noting that none of the called events have parameters, while the uncalled events all have paraments, I have tried modifying parameter types. i.e. changing
to
and
Neither attempt worked.
Does anyone have any ideas on why the events with parameters are not called? Any suggestions would be appreciated.
Ron
My globals module defines:
Code:
GLOBAL goApp AS Int__Application GLOBAL goWordEvents AS ApplicationEvents2
Code:
' create a new instance of Word goApp = NEWCOM $PROGID_Word_Application ' if not a valid reference, exit & return failure code IF ISNOTHING(goApp) THEN FUNCTION = %False EXIT FUNCTION END IF ' create event handler goWordEvents = CLASS "Class_ApplicationEvents2" ' if not a valid reference, ' clear Word reference, exit & return failure code IF ISNOTHING(goWordEvents) THEN goApp.Quit goApp = NOTHING FUNCTION = %False EXIT FUNCTION END IF ' attach event handler to Word app EVENTS FROM goApp CALL goWordEvents ' return success FUNCTION = %True
But I wasn't receiving all events. This is how I rigged the event-handling class:
Code:
CLASS Class_ApplicationEvents2 $CLSID_Word_Event_ApplicationEvents2 AS EVENT INTERFACE ApplicationEvents2 $IID_Word_ApplicationEvents2 INHERIT IDISPATCH METHOD Startup <1> () LogIt("Startup: " & STR$(TIMER)) END METHOD METHOD Quit <2> () LogIt("Quit: " & STR$(TIMER)) END METHOD METHOD DocumentChange <3> () LogIt("DocumentChange: " & STR$(TIMER)) END METHOD METHOD DocumentOpen <4> (BYVAL DOC AS IDISPATCH) LogIt("DocumentOpen: " & STR$(TIMER)) END METHOD METHOD DocumentBeforeClose <6> (BYVAL DOC AS IDISPATCH, BYREF IN CANCEL AS INTEGER) LogIt("DocumentBeforeClose: " & STR$(TIMER)) END METHOD METHOD DocumentBeforePrint <7> (BYVAL DOC AS IDISPATCH, BYREF IN CANCEL AS INTEGER) LogIt("DocumentBeforePrint: " & STR$(TIMER)) END METHOD METHOD DocumentBeforeSave <8> (BYVAL DOC AS IDISPATCH, BYREF IN SaveAsUI AS INTEGER, BYREF IN CANCEL AS INTEGER) LogIt("DocumentBeforeSave: " & STR$(TIMER)) END METHOD METHOD NewDocument <9> (BYVAL DOC AS IDISPATCH) LogIt("NewDocument: " & STR$(TIMER)) END METHOD METHOD WindowActivate <10> (BYVAL DOC AS IDISPATCH, BYVAL Wn AS Int_Window) LogIt("WindowActivate: " & STR$(TIMER)) END METHOD METHOD WindowDeactivate <11> (BYVAL DOC AS IDISPATCH, BYVAL Wn AS Int_Window) LogIt("WindowDeactivate: " & STR$(TIMER)) END METHOD METHOD WindowSelectionChange <12> (BYVAL Sel AS Selection) LogIt("WindowSelectionChange: " & STR$(TIMER)) END METHOD METHOD WindowBeforeRightClick <13> (BYVAL Sel AS Selection, BYREF IN CANCEL AS INTEGER) LogIt("WindowBeforeRightClick: " & STR$(TIMER)) END METHOD METHOD WindowBeforeDoubleClick <14> (BYVAL Sel AS Selection, BYREF IN CANCEL AS INTEGER) LogIt("WindowBeforeDoubleClick: " & STR$(TIMER)) END METHOD END INTERFACE END CLASS
Cleverly noting that none of the called events have parameters, while the uncalled events all have paraments, I have tried modifying parameter types. i.e. changing
Code:
METHOD DocumentOpen <4> (BYVAL DOC AS IDISPATCH)
Code:
METHOD DocumentOpen <4> (BYVAL DOC AS Int__Document)
Code:
METHOD DocumentOpen <4> (BYVAL DOC AS VARIANT)
Does anyone have any ideas on why the events with parameters are not called? Any suggestions would be appreciated.
Ron
Comment