首页 > 解决方案 > 如何修复“无法运行宏”错误?

问题描述

当我将“Application.OnKey”与我的 tetr 对象一起使用时,我得到了错误,但是当我使用简单的 sum 函数进行测试时,一切正常。如果需要,我可以提供该类的代码。

错误:无法运行宏“C:\Path\File.xlsm'!'MoveDown tetr”。该工作簿中的宏可能不可用

Sub Game()
    Dim tetr As New tetromino
    Application.OnKey "{DOWN}", "'MoveDown tetr'"
End Sub

Sub MoveDown(tetr As tetromino)
    tetr.PosY = tetr.PosY - 1
End Sub

标签: excelvba

解决方案


对我来说,GetAsyncKeyState 是解决方案。


推荐阅读