Excel VBA - 几秒钟后调用宏清除状态栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40410953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA - Call macro to clear status bar after a few seconds
提问by Citanaf
I am trying to figure out if there is a way to call a macro to clear the status bar after the execution of a different macro. I realize that I can simply use:
我想弄清楚是否有办法在执行不同的宏后调用宏来清除状态栏。我意识到我可以简单地使用:
Application.Wait(Now + TimeValue("00:00:05"))
Application.StatusBar = False
However, what I want to do is have my original macro end by saying something as:
但是,我想要做的是通过说以下内容来结束我的原始宏:
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
Is there a way to delay the "Application.StatusBar = False" while still allowing the user to access the program?
有没有办法在仍然允许用户访问程序的同时延迟“Application.StatusBar = False”?
Let me know if you need more clarity. Thanks for your help.
如果您需要更清晰,请告诉我。谢谢你的帮助。
回答by
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
回答by Citanaf
Sorceri was able to provide me with the correct method for my request. By using the Application.OnTime method, you can call your macro on a delay without tying up the program.
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