Excel VBA - 宏错误 - 宏可能不可用 - 自动刷新 [英] Excel VBA - Macro error - The macro may not be available - Auto Refresh
问题描述
我有一个启用宏的 excel 文件,我试图在其中创建一个宏来每 2 分钟运行一次函数.
I have a macro enabled excel file in which I am trying to create a macro to run functions every 2 minutes.
以下是我的代码:
Sub macro123()
Application.SendKeys ("%{A}")
Application.SendKeys ("R")
Application.SendKeys ("A")
Call test
End Sub
Sub test()
Application.OnTime Now + TimeValue("00:02:00"), "macro123"
End Sub
我第一次运行宏 123 时就会执行它.2 分钟后,它再次尝试运行它,这时我收到以下错误.
The macro123 gets executed the first time I run it. After 2 minutes it tried to run it again, that's when I am getting the following error.
[![在此处输入图片描述][1]][1]
[![enter image description here][1]][1]
宏设置似乎是灰色的,可能是由于组织的域设置?
The macro settings seem to be greyed out, probably due to domain settings of organization?
[![在此处输入图片描述][2]][2]
[![enter image description here][2]][2]
有没有其他方法可以让我每 n 分钟执行一次这些语句?
Is there any other way for me to execute those statements every n minutes?
推荐答案
如果您的宏在代码模块 ThisWorkbook
中,那么您应该指定它,包括代码模块的名称.
If your macro is in the code module ThisWorkbook
, then you should specify it including the code module's name.
试试这个:
Application.OnTime Now + TimeValue("00:02:00"), "ThisWorkbook.macro123"
' ^^^^^^^^^^^^^^
这篇关于Excel VBA - 宏错误 - 宏可能不可用 - 自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!