简体   繁体   English

Excel VBA - 宏错误 - 宏可能不可用 - 自动刷新

[英]Excel VBA - Macro error - The macro may not be available - Auto Refresh

I have a macro enabled excel file in which I am trying to create a macro to run functions every 2 minutes.我有一个启用宏的 excel 文件,我试图在其中创建一个宏来每 2 分钟运行一次函数。

The following is my code:以下是我的代码:

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

The macro123 gets executed the first time I run it.我第一次运行 macro123 时就会执行它。 After 2 minutes it tried to run it again, that's when I am getting the following error. 2 分钟后,它尝试再次运行它,那时我收到以下错误。

[![enter image description here][1]][1] [![在此处输入图像描述][1]][1]

The macro settings seem to be greyed out, probably due to domain settings of organization?宏设置似乎变灰了,可能是由于组织的域设置?

[![enter image description here][2]][2] [![在此处输入图像描述][2]][2]

Is there any other way for me to execute those statements every n minutes?有没有其他方法可以让我每n分钟执行一次这些语句?

If your macro is in the code module ThisWorkbook , then you should specify it including the code module's name.如果您的宏在代码模块ThisWorkbook ,那么您应该指定它,包括代码模块的名称。

Try this:尝试这个:

Application.OnTime Now + TimeValue("00:02:00"), "ThisWorkbook.macro123"
'                                               ^^^^^^^^^^^^^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM