Excel 宏调用在定时器中不起作用,但在另一个宏中起作用
Excel macro call does not work from timer, but does from another macro
我正在尝试让 excel 到 运行 每 XX 秒更新一次。
Sub StartTesting()
Call RunAll_ISP 'this call works
End Sub
Sub macro_timer() 'This sub schedules next run in XX seconds.
Dim ScanInterval
ScanInterval = Format(ThisWorkbook.Sheets("Configuration").Range("B5").Value, "hh:mm:ss")
Application.OnTime Now + TimeValue(ScanInterval), "RunAll_ISP", Schedule:=True ' !this macro call throws error!
End Sub
如果我 运行 Start_testing 宏,调用有效。
如果我 运行 macro_timer 宏,它会等待所需的秒数,然后抛出此错误:
Cannot run the macro "C:\location_of_file\filename.xlsm'!RunAll_ISP'. The macro may not be available in this workbook or all macros may be disabled
信任中心的宏设置设为“启用 VBA 宏”
我做错了什么?
您的问题无法重现。这个简单的示例有效。
因此,由于您的程序 StartTesting
有效,这意味着宏肯定已启用,所以剩下的唯一选择是您的宏 RunAll_ISP
不存在(或错误命名)。
Option Explicit
Public Sub RunAll_ISP()
MsgBox "I run"
End Sub
Public Sub CreateTimer()
Application.OnTime Now + TimeValue("00:00:05"), "RunAll_ISP", Schedule:=True
End Sub
我正在尝试让 excel 到 运行 每 XX 秒更新一次。
Sub StartTesting()
Call RunAll_ISP 'this call works
End Sub
Sub macro_timer() 'This sub schedules next run in XX seconds.
Dim ScanInterval
ScanInterval = Format(ThisWorkbook.Sheets("Configuration").Range("B5").Value, "hh:mm:ss")
Application.OnTime Now + TimeValue(ScanInterval), "RunAll_ISP", Schedule:=True ' !this macro call throws error!
End Sub
如果我 运行 Start_testing 宏,调用有效。 如果我 运行 macro_timer 宏,它会等待所需的秒数,然后抛出此错误:
Cannot run the macro "C:\location_of_file\filename.xlsm'!RunAll_ISP'. The macro may not be available in this workbook or all macros may be disabled
信任中心的宏设置设为“启用 VBA 宏”
我做错了什么?
您的问题无法重现。这个简单的示例有效。
因此,由于您的程序 StartTesting
有效,这意味着宏肯定已启用,所以剩下的唯一选择是您的宏 RunAll_ISP
不存在(或错误命名)。
Option Explicit
Public Sub RunAll_ISP()
MsgBox "I run"
End Sub
Public Sub CreateTimer()
Application.OnTime Now + TimeValue("00:00:05"), "RunAll_ISP", Schedule:=True
End Sub