(Autohotkey) 需要帮助选择带有“+1”的东西的不同 Excel 单元格 .. 或者我不知道如何称呼它

问题描述

我需要自动热键在 Excel 自动化方面的帮助..

所以我想在第一个输入中选择“A1”单元格,然后对于第二个、第三个和下一个输入,我想选择“A”单元格+1, 所以在第二个输入中选择的“A”单元格将是 A2 在第三个输入中选择的“A”单元格将是 A3 等...

所以很可能是这样..

INPUT1:
X=1

oExcel := ComObjActive("Excel.Application")
oExcel.Sheets("SHEET").Activate
oExcel.Range("A1").Select

goto,INPUTX:

INPUTX:
X = +1
oExcel := ComObjActive("Excel.Application")
oExcel.Sheets("SHEET").Activate
oExcel.Range("A(X)").Select

但我不知道如何在 AHK 代码中正确编写它......有人可以帮我解决这个问题吗?非常感谢...

解决方法

不用担心,你快到了。我想这就是你想要的。您可能想要循环,并且还需要将数字连接到单元格名称中

DoMyStuff:
/* You only need to get the Excel COM object once. 
 * So we do this here,outside of the loop. */
oExcel := ComObjActive("Excel.Application")
; activate the sheet once.
oExcel.Sheets("SHEET").Activate

Loop,100 ; this repeats the following code from 1 to 100.
{
    /* A_Index in a "Loop" block becomes 1..2..3.. 
     * to 100 (each loop pass) or whatever is set above. 
     * With AHK v1.1,you can concat like so: 
     * "something" 42 "anotherthing"
     * gives
     * "something42anotherthing"
     */
    oExcel.Range("A" A_Index).Select 
}
return