Dan*_*vaw 3 excel vba popup msgbox
我正在尝试生成一个弹出窗口,该弹出窗口会在给定的WaitTime几秒钟内关闭。
我尝试应用“ VBA Excel宏消息框自动关闭”中的方法;我的代码如下:
Sub TestSubroutine()
Dim TemporalBox As Integer
Dim WaitTime As Integer
Dim WScriptShell As Object
Set WScriptShell = CreateObject("WScript.Shell")
WaitTime = 1
TemporalBox = WScriptShell.Popup("The message box will close in 1 second.", _
WaitTime, "File processed")
End Sub
Run Code Online (Sandbox Code Playgroud)
弹出窗口已显示,但一秒钟后不会关闭。
编辑#1
根据@Skip Intro评论,我更新了代码:
Sub TestSubroutine()
Dim WaitTime As Integer
WaitTime = 1
CreateObject("WScript.Shell").Popup "The message box will close in 1 second.", _
WaitTime, "File processed"
End Sub
Run Code Online (Sandbox Code Playgroud)
然而,这并没有解决最初的问题,弹出窗口在 1 秒后没有关闭。
编辑#2
这是@Glitch_Doctor 建议的代码,但它仍然不起作用:
Sub TestSubroutine()
Dim TemporalBox As Integer
Dim WaitTime As Integer
Dim WScriptShell As Object
Dim test
Set WScriptShell = CreateObject("WScript.Shell")
WaitTime = 1
Select Case TemporalBox = WScriptShell.Popup("The message box will close in 1 second.", _
WaitTime, "File processed")
Case 1, -1
End Select
End Sub
Run Code Online (Sandbox Code Playgroud)
我终于找到了一个非常简单的解决方案 - 感谢@Orphid,请在以下线程中查看他的答案。
我没有解决与原始代码相关的具体问题,但我设法创建了一个在指定时间段后关闭的 PopUp。代码如下:
Sub subClosingPopUp(PauseTime As Integer, Message As String, Title As String)
Dim WScriptShell As Object
Dim ConfigString As String
Set WScriptShell = CreateObject("WScript.Shell")
ConfigString = "mshta.exe vbscript:close(CreateObject(""WScript.Shell"")." & _
"Popup(""" & Message & """," & PauseTime & ",""" & Title & """))"
WScriptShell.Run ConfigString
End Sub
Run Code Online (Sandbox Code Playgroud)
这很好用。