I have a macro enabled excel file in which I am trying to create a macro to run functions every 2 minutes.
我有一个支持宏的excel文件,我在其中尝试创建一个宏来每两分钟运行一次函数。
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. After 2 minutes it tried to run it again, that's when I am getting the following error.
宏123在我第一次运行时被执行。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分钟执行这些语句?
1 个解决方案
#1
1
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"
' ^^^^^^^^^^^^^^
#1
1
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"
' ^^^^^^^^^^^^^^