I created an AHK file which only contains variables (for the future also functions).
In my target script I included that ahk file which contains variables.
The 1st ahk file is named Excel-COM.ahk:
Code: Select all
;Excel-COM
xl := ComObjActive("Excel.Application") ; Active Excel instance
wb := xl.ActiveWorkbook ; Active workbook
ws := xl.ActiveSheet ; Active worksheet
cellArray := ["A1", "B1", "C1", "D1"] ; List of cells
cell := cellArray[i] ; Variable which accesses values of the array
Code: Select all
#SingleInstance force
#Include Excel-COM.ahk
F5::
ws.Next.Select
return
This works, but only 1 time.
E.g. From Sheet1 to Sheet2.
After pressing F5 again, nothing happens.
When manually selecting a worksheet (e.g. Sheet4) and pressing F5 again, it jumps to Sheet2 again.
If my 2nd code is this, it works perfectly.
Code: Select all
F5::
xl := ComObjActive("Excel.Application") ; Active Excel instance
wb := xl.ActiveWorkbook ; Active workbook
ws := xl.ActiveSheet ; Active worksheet
cellArray := ["A1", "B1", "C1", "D1"] ; List of cells
cell := cellArray[i] ; Variable which accesses values of the array
ws.Next.Select
return
I also tried to declare them all as global (in ahk file 1), but the result was the same.
Regards