Excel VBA - 几秒钟后调用宏以清除状态栏

时间:2016-11-03 20:47:32

标签: excel vba excel-vba

我试图弄清楚在执行不同的宏之后是否有办法调用宏来清除状态栏。我意识到我可以简单地使用:

Application.Wait(Now + TimeValue("00:00:05"))
Application.StatusBar = False

但是,我想做的是通过说出以下内容来表达原始的宏:

Application.StatusBar = "Macro Function Complete."
Call clearStatusBar
End Sub

Sub clearStatusBar()
'I do not want the application.wait here because it locks up the excel program. 
Application.Wait(Now + TimeValue("00:00:05"))
Application.StatusBar = False
End Sub

有没有办法延迟“Application.StatusBar = False”,同时还允许用户访问该程序?

如果您需要更清晰,请告诉我。谢谢你的帮助。

2 个答案:

答案 0 :(得分:4)

enter image description here

Sub TestClearStatusBar()
    Application.StatusBar = "Testing: ClearStatusBar"
    ClearStatusBar
End Sub

Sub ClearStatusBar(Optional ClearStatusBar As Boolean)
    If ClearStatusBar Then
        Application.StatusBar = False
        MsgBox "Cleared"
    Else
        Application.OnTime Now + TimeValue("00:00:05"), "'ClearStatusBar True'"
    End If
End Sub

答案 1 :(得分:2)

Sorceri能够为我提供正确的方法。通过使用Application.OnTime方法,您可以延迟调用宏而不会占用程序。

Application.StatusBar = "Macro Function Complete."
Application.OnTime Now + TimeValue("00:00:07"), "clearStatusBar"
End Sub

Sub clearStatusBar()
Application.StatusBar = False
End Sub