Description
You have created the perfect time-saving Excel macros and now you want to trigger them with AutoHotkey. This simple script shows you one way of doing it.
Steps
1
Prepare your overlay
Choose an unassigned key on the Enterpad for the Excel macro. Use an appropriate name like "Macro1".
2
Code installation
Copy and paste the following script in the AutoHotkey script template (Enterpad.ahk) at the location of the key you wish to assign.
001: IfWinNotActive, ahk_class XLMAIN { MsgBox % "Excel is not active. No action will be performed." Return } try epExcel := ComObjActive("Excel.Application") catch { MsgBox % "Unable to execute the shortcut." Return } try epExcel.Run("Macro1") catch { MsgBox % "Unable to run the macro. Are you editing a cell?" } epExcel := return
More Info
The Excel macro should be triggered if:
- An Excel worksheet is the active window;
- Excel is not busy (e.g. editing, selecting a command);
- The macro exists.
If you would like to add a parameter to the macro when it is triggered, just modify line #15 of the script (step 2) from
epExcel.Run("Macro1")
to
epExcel.Run("Macro1", "Param1")
And replace Param1 with the value of the parameter.