【发布时间】:2013-12-05 01:04:22
【问题描述】:
我有一个调用 Excel 宏的自动热键脚本。基本上我有一个通用快捷方式可以在 Excel 中向我的自定义 GTD 应用程序添加任务
我的AHK代码如下:
RunMSExcelMacro(MacroName, args) { ; for AHK_L
oExcel := ComObjActive("Excel.Application")
; oExcel.Workbooks("gtd_active.xlsm").Run(MacroName,args)
oExcel.Run("'gtd_active.xlsm'!"+MacroName,args)
;oExcel.Run(MacroName,args)
}
#Space::
InputBox, newTask, Add New Task to GTD, What is the new task?, , 380, 130
if (newtask = "" or ErrorLevel){ ;if blank or "cancel" pressed (ErrorLevel = 1) don't do anything
return
}
else
{RunMSExcelMacro("addFromAHK", newTask)
}
return
Excel中的方法如下:
'this script allows AutoHotKey to add items to the GTD list
'without having to even access Excel - wtf hax :-)
Sub addFromAHK(ByRef newTask As String)
Dim myCell As Range
'I don't like hardcoding this but I cant be bothered to
'make this reference the constant right now
Set myCell = MasterList.Range("C50000").End(xlUp)
'ugh such a hack. No easy way to get last cell without defiltering
Do Until IsEmpty(myCell) = True
Set myCell = myCell.Offset(1, 0)
Loop
'save the task
myCell.value = newTask
End Sub
不幸的是,如果我当前正在 Excel 中编辑单元格,我无法调用宏,因此全局快捷方式失败。请注意,在我能够调用 Excel 宏之前这会失败。
如果我这样做,是否有一种简单的方法可以将 AHK 代码更改为基本上“退出单元格编辑”?我不想为此编写大量代码,但我真的不确定这里的最佳方法。
【问题讨论】:
-
“编辑单元格”到底是什么意思?另外,您使用的是什么 Excel 版本?
-
@MCL 当我实际编辑一个单元格时。 IE光标在里面。 Excel 2010。
标签: vba excel excel-2010 autohotkey