gpt4 book ai didi

vba - 无法运行宏 该工作簿中的宏可能不可用,或者所有宏都可能被禁用

转载 作者:行者123 更新时间:2023-12-04 22:33:38 25 4
gpt4 key购买 nike

我试图通过以下代码每 5 秒后添加一个事件(在此示例中为打印时间)。

Sub tr1()
dim i as Integer
i = Range("b1").Value
If i < 3 Then
Application.OnTime Now + TimeValue("00:00:05"), "tr2", , True
End If

Range("a" & i).Value = UCase(Format(Now, "HH:MM:SS"))
Range("b1").Value = Range("b1").Value + 1
MsgBox ("tr1 called")
End Sub

Sub tr2()
Application.OnTime Now + TimeValue("00:00:05"), "tr1"
MsgBox ("tr2 called")
End Sub

在运行 tr1 时,我收到以下错误:

Error screen shot 5 秒后。请让我告诉我我做错了什么。

最佳答案

您还必须引用该模块。如果代码在 Module1 中,这将起作用:

Sub tr1()
Application.OnTime Now + TimeValue("00:00:01"), "!Module1.tr2", , True
End Sub

Sub tr2()
MsgBox "tr2"
End Sub

如果它在工作表中,则相应地:
Sub tr1()
Application.OnTime Now + TimeValue("00:00:01"), "!Sheet1.tr2", , True
End Sub

Sub tr2()
MsgBox "tr2"
End Sub

关于vba - 无法运行宏 该工作簿中的宏可能不可用,或者所有宏都可能被禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50984883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com