Jump to content

Failing to hook Excel events.


Crepello
 Share

Recommended Posts

Hi,

Could anyone shed some light on this problem which has had me spinning my wheels for

about the last week? I'm trying, and failing, to hook Excel events. I've managed it

with Word, and have combined both in the scenario script below. Word sails through and

I get the console output from my MSWEvent_() function. OTOH, the equivalent for Excel

produces a COM error 80040200 (no meaningful message) after what seems a timeout on

the ObjEvent() call. By way of testing system configuration, I have done the equivalent

in VBA within Word, where I can trap Excel events without problems. The problem is

apparent at home (Win 98/Office 97) and work (Win XP/Office 2k).

#include <GUIConstants.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")   ; Initialize a COM error handler

$oWD = ObjCreate("Word.Application")
$WDfilein = "C:\My WORD.doc"; must exist
With $oWD
    .Documents.Open($WDfilein)
    .Visible = True
    .Caption = "My New Word title"
EndWith
$oWordEvts = ObjEvent($oWD,"MSWEvent_")
; No Errors here!

$oXL = ObjCreate("Excel.Application")
$XLfilein = "C:\myXLS.xls"; must exist
With $oXL
    .Workbooks.Open($XLfilein)
    .Visible = True
    .Caption = "My New XL title"
EndWith
$oExcelEvts = ObjEvent($oXL,"XLEvent_")
;~ We intercepted a COM Error !
;~ err.number is:   80040200
;~ err.lastdllerror is:     0
;~ err.scriptline is:   21


$Form1 = GUICreate("IdleForm", 200, 200, 194, 116)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd

Exit

func MSWEvent_($Eventname)
    beep()
    ConsoleWrite("Unhandled MSWord Event: " & $Eventname & @LF)
EndFunc

func XLEvent_($Eventname)
    beep()
    ConsoleWrite("Unhandled MSExcel Event: " & $Eventname & @LF)
EndFunc

Func MyErrFunc()
Dim $msgTxt
    $msgTxt =   "We intercepted a COM Error !"    & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext
             
    Msgbox(0,"AutoItCOM Test", $msgTxt)
    ConsoleWrite($msgTxt & @LF)
            
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    
    $g_eventerror = $err ; to check for after this function returns
Endfunc
Link to comment
Share on other sites

  • 2 weeks later...

Hmm,

Still all quiet after 2 weeks. Time to own up, before I get a reply calling me an Ejit, that I've realised I posted to the wrong forum. The significance of the second 'X' in the forum title didn't hit me until after I hit 'Send'. Sorry.

Perhaps in the correct forum, someone with a copy of Excel might have read it and wondered...?

Cheers,

Crepello

Link to comment
Share on other sites

Crepello

I tried your script on WinXP with Office 2007 and received same results:

Unhandled MSWord Event: WindowDeactivate

We intercepted a COM Error !

err.description is:

err.windescription: ÌÍ??????$??

err.number is: 80040200

err.lastdllerror is: 0

err.scriptline is: 22

err.source is:

err.helpfile is:

err.helpcontext is:

I hope this is helpful

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...