在AutoHotkey Excel中input不匹配
我正在尝试从用户获取input,在Excel列中查找input值,并返回匹配值右侧单元格的值。
这是我想出来的。 只要我用数字replace%index%,就会从Excel文件中返回一个值。
我收到的错误告诉我有一个“types不匹配”,我使用%index% in
value := workbook.Sheets("Sheet1").Cells(%index%, 1).Value
任何想法如何解决types不匹配?
#a:: workbook := ComObjGet("somepath\tester.xlsx") InputBox, OutputVar, Question 1, What are you looking for? if (OutputVar) MsgBox, Let me do this for you. intent = OutputVar index = 1 value = "" Loop { index := %index% + 1 value := workbook.Sheets("Sheet1").Cells(%index%, 1).Value } Until %intent% = %value% SendInput, workbook.Sheets("Sheet1").Cells(%index%, 2).Value Return
在expression式中使用index
,而不是%index%
。 另外,你可以在循环内部使用内build的A_INDEX
variables
这是你的更正的代码:
#a:: workbook := ComObjGet("somepath\tester.xlsx") MAX_ROWS := 10 InputBox intent, Question 1, What are you looking for? if ( ErrorLevel == 0 && intent ) { Loop %MAX_ROWS% { if ( intent == workbook.Sheets("Sheet1").Cells(A_Index, 1).Value ) { SendInput % workbook.Sheets("Sheet1").Cells(A_Index, 2).Value return } } MsgBox 48, Not Found, "%intent%" not found in column a } return
笔记:
- 当一个命令接受一个expression式时,你不能使用replace
-
ErrorLevel == 0
表示确定已被按下。 请参阅InputBox -
SendInput %
使行使用expression式模式 ; 在“%”之后的所有内容都被评估为一个expression式 - 如果在电子表格中找不到
intent
则循环将不会退出