简体   繁体   中英

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.

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.

[![enter image description here][1]][1]

The macro settings seem to be greyed out, probably due to domain settings of organization?

[![enter image description here][2]][2]

Is there any other way for me to execute those statements every n minutes?

If your macro is in the code module ThisWorkbook , then you should specify it including the code module's name.

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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