Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Excel中显示一段时间的弹出窗口_Excel_Vba_Popup_Msgbox - Fatal编程技术网

在Excel中显示一段时间的弹出窗口

在Excel中显示一段时间的弹出窗口,excel,vba,popup,msgbox,Excel,Vba,Popup,Msgbox,我试图生成一个弹出窗口,在给定的等待时间(以秒为单位)后关闭 我咨询了林克和林克 我试着从另一个角度应用这个方法;我的代码如下: Sub TestSubroutine() Dim TemporalBox As Integer Dim WaitTime As Integer Dim WScriptShell As Object Set WScriptShell = CreateObject("WScript.Shell") WaitTime = 1 TemporalBox = WScript

我试图生成一个弹出窗口,在给定的等待时间(以秒为单位)后关闭

我咨询了林克和林克

我试着从另一个角度应用这个方法;我的代码如下:

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
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
将显示弹出窗口,但它不会在一秒钟后关闭

编辑1

基于@Skip Intro comment,我更新了代码:

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秒后不会关闭

编辑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
您只是缺少选择的案例:


我测试过了,它可以工作…

如果你的方法根本不起作用的话,另一种方法

创建一个名为frm_Popup的新用户表单,并在其中添加一个名为lbl_Message的标签。向userform代码中添加以下void:

Public Sub StartProcess(iTime As Integer)
    Me.lbl_Message.Caption = "The message box will close in " & iTime & " second(s)."
End Sub
然后在您的模块中:

Sub ShowMessage()
    Dim iTimeToWait As Integer
        iTimeToWait = 2

    With frm_Popup
        .Show False
        Call .StartProcess(iTimeToWait)
    End With

    Application.OnTime Now + TimeValue("00:00:" & iTimeToWait), "HidePopup"
End Sub

Private Sub HidePopup()
    Unload frm_Popup
End Sub

我终于找到了一个非常简单的解决方案——归功于@Orphid,见下面他的答案

我没有解决与我的原始代码相关的特定问题,但我设法创建了一个弹出窗口,在指定的时间段后关闭。代码如下:

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
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

这很好。

以下代码适合我:

Sub TimeBasedPopUp()

Dim WaitTime As Integer

WaitTime = 1
Select Case CreateObject("WScript.Shell").Popup("The message box will close in 1 second.",_
WaitTime, "MS Excel")
Case 1, -1
结束选择


End Sub

下面的代码对我有效,我在弹出消息出现之前添加了2秒延迟。4秒后,它自动消失。我是从Dinesh Kumar Takyar先生那里学到的。他添加了一个5秒延迟的b4弹出窗口。他的youtube链接 我认为关键问题是你需要一个弹出计时器工作的延迟。可能Excel应用程序需要运行一段时间,弹出窗口出现


您可以在一行中调用弹出窗口:CreateObjectWSScript.Shell.popup这是一条消息,1,这是一个标题,0+64'如果您试图捕获响应,它只会变得复杂,如果等待=1秒,我认为您不需要。谢谢您的提示。但是,这并不能解决原来的问题,弹出窗口将保持打开状态。我已经更新了原来的帖子。第二段代码对我很有用。该框出现,然后一秒钟后自动关闭。您使用的是什么操作系统?我使用的是Windows 7,它的工作原理也符合预期Swindows 7。我在尝试该代码时遇到运行时错误424:object required。很抱歉,我使用的是您的原始代码,它适用于那些Dim。您是否仍然在Dim中遇到错误?或者弹出窗口没有关闭?我没有任何错误,弹出窗口被显示,但从未关闭。我唯一能想到的是,我打开了一个参考,而你没有,但另一个答案应该有效。除了100%与此无关的internet控件之外,我所拥有的只是:Visual Basic For Applications、Microsoft Excel 14.0对象库、OLE Automation、Microsoft Office 14.0对象库。唉,我无法区分它们。我只是在需要的时候打开了它们。我正在考虑下一步的应用程序。一旦我完成了我正在编写的报告,我就会立即开始。。。打得好,先生。我们能把这个做成是/否的信息框吗?如果未按“是”,则在暂停时间后自动使其按“否”
Sub ShellMessageBox()

Dim MsgBoxWithTimer As Integer

MsgBoxWithTimer=CreateObject("WScript.Shell").Popup("Put your message here", PopUpTime, _
"Notice!", 0)

End Sub
Sub startTimer()
Application.OnTime Now + TimeValue("00:00:02"), "ShellMessageBox"
End Sub
Private Sub Workbook_Open()

startTimer

End Sub