It works when Excel is closed (first part of if-statement), Excel opens the right file, is visible and the messagebox with the filename apears.
But when the specific Excel file is already open and I activate my hotkey it still opens it again so I have 2 of the same files opened.
It just doesn't seem to go to the else part of the if-statement when the file is already opened.
The code I have rn is below.
!!This isn't my own code, the good sir Joe Glines wrote it but it doesn't seem to work for me!!
Code: Select all
^!q::
xlWB := "xl"
if(!WinExist(xlWB)) {
XL := ComObjCreate("Excel.Application")
Path = ;fill in path of specific Excel file here
XL.Workbooks.Open(Path)
XL.Visible := 1
MsgBox %Path% `n is now loaded
} else {
XL := ComObjActive("Excel.Application")
WinActivate, %xlWB%
MsgBox % "Excel already active"
}