0
votes

I want Autohotkey to monitor an Excel 2010 window for the Close Command, intercept and cancel the command, run a script, and then finally close the window.

I understand that OnClose and BeforeClose are existing commands in vba, but I canNOT use .xlsm (Macro-Enabled) worksheets and this is on at least 5 different workstations so Personal.xlsb isn't an option either.

I've found several references that vba is "easy" to translate to COM which I'm just learning how to use, but Ive been beating my head against the keyboard for a week now and I can come up with no syntax that will let me monitor a window for the "Close" command.

I was thinking most recently, OnMessage, but I cannot come up with the syntax for that either and Google has been useless, I can't even find anyone else asking about this! Please Help!

1
What is the nature of the script running on close? Is it something that could just be run on the file after the file has closed?bushell

1 Answers

0
votes

I posted two usable examples in your topic on the ahkscript.org forum here

Here is the simpler one of the two

oExcel := ComObjActive("Excel.Application")
oWorkbook := oExcel.ActiveWorkbook
ComObjConnect(oWorkbook, Workbook_Events)
return

class Workbook_Events
{
    BeforeClose(Cancel)
    {
        msgbox % "closing"
    }
}

Hope it helps