使用 AutoHotKey 为 VBA 宏指定快捷方式

问题描述

有什么方法可以将 AutoHotKey 快捷键分配给 VBA 宏。

#IfWinActive,ahk_exe EXCEL.EXE
~Alt::vkFF
!h:: ->VBA procedure
#If

谁能帮帮我?谢谢

解决方法

AHK 代码:(带有错误处理和调试语句)

public class WeatherForecastWithConverterAttribute
{
    [JsonConverter(typeof(DateTimeOffsetJsonConverter))]
    public DateTimeOffset Date { get; set; }
    public int TemperatureCelsius { get; set; }
    public string Summary { get; set; }
}

VBA 代码:

#IfWinActive,ahk_exe EXCEL.EXE
~Alt::vkFF
!h:: 
    try {
        XL := ComObjActive("Excel.Application")
    } catch {
        MsgBox,16,Cann't obtain Excel! 
        return
    }
    MsgBox,64,Excel obtained successfully!   ;for debugging purposes
    try {
        XL.Run("theSub")
    } catch {
        MsgBox,Cann't find "theSub" in the opened workbook!
    }
#If

按 Alt+h 后:(AHK 脚本运行,Excel 运行,带有 Sub 过程的工作簿打开并处于活动状态)
enter image description here