在Excel中显示一段时间的弹出窗口 [英] Display popup for a time period in Excel
问题描述
我正在尝试生成一个弹出窗口,该弹出窗口会在给定的WaitTime
之后几秒钟内关闭.
I am trying to generate a popup that closes after a given WaitTime
in seconds.
我咨询了此链接和我尝试从" VBA Excel宏消息框自动关闭中应用该方法";我的代码如下:
I tried to apply the method from "VBA Excel macro message box auto close"; my code is the following:
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
显示弹出窗口,但一秒钟后它永远不会关闭.
The popup is displayed but it never closes after one second.
编辑#1
基于@Skip Intro评论,我更新了代码:
Based on @Skip Intro comment, I have updated the code:
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
但是,这不能解决原始问题,弹出窗口不会在1秒后关闭.
However this does not solve the original issue, the popup does not close after 1 second.
编辑#2
这是@Glitch_Doctor建议的代码,但是仍然无法使用:
This is the code suggested by @Glitch_Doctor, however it still doesn't work:
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
推荐答案
我终于找到了一个非常简单的解决方案-感谢@Orphid,请在以下
I finally found a very simple solution - credits to @Orphid, see his answer in the following thread.
我没有解决与原始代码有关的特定问题,但是我设法创建了一个在指定时间段后关闭的PopUp.代码如下:
I did not solve the specific issue related to my original code, but I managed to create a PopUp that closes after a specified period of time. The code is the following:
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
这很好用.
这篇关于在Excel中显示一段时间的弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!