Create / Connect to Excel with AutoHotkey via COM

excel-with-autohotkey

AutoHotkey Merchandise-White Stress ballAutomating Excel with AutoHotkey is pretty easy however first connecting with the Excel object can be a bit confusing.

This video walks through both connecting with a running Excel application and creating a new one.  It also walks you through how to set the object visible (and use the Task Manager to see if it exists)

Here is the code reviewed in the video:

#SingleInstance,, Force
Browser_Forward::Reload
Browser_Back::

try XL := ComObjActive("Excel.Application") ;handle to running application
Catch {
    MsgBox % "no existing Excl ojbect:  Need to create one"
XL := ComObjCreate("Excel.Application")
XL.Visible := 1 ;1=Visible/Default 0=hidden
}
XL.Visible := 1 ;1=Visible/Default 0=hidden
MsgBox % "is an object? " IsObject(XL)

Creating & Connecting to Excel with AutoHotkey via COM

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.