【问题标题】:Show Msgbox 3 seconds before macro starts running and close that msgbox automatically in 3 seconds在宏开始运行前 3 秒显示 Msgbox 并在 3 秒内自动关闭该 msgbox
【发布时间】:2020-12-24 06:57:46
【问题描述】:

我有以下宏作为基于时间的运行

Application.OnTime TimeValue("12:2:20"), "ADPATEL"

我想要的是在 3 秒前弹出消息框并在 3 秒内自动关闭

尝试了以下方法,但没有自动关闭msgbox

   Dim AckTime As Integer, InfoBox As Object

 Set InfoBox = CreateObject("WScript.Shell")
 AckTime = 3
 Select Case InfoBox.Popup("Click OK or do nothing within 3 seconds.", _
 AckTime, "This is your Message Box", 0)

 Case 1, -1
 Exit Sub
End Select

任何帮助都是appriciated

【问题讨论】:

标签: vba


【解决方案1】:

请试试这个代码:

Sub testPopUpMess()
 Select Case CreateObject("wscript.shell").popup("Click OK or do nothing within 3 seconds.", _
                                                            3, "This is your Message Box", 64)
     Case 1: MsgBox "OK": Exit Sub
     Case Else: MsgBox """OK"" button not pressed..."
 End Select
End Sub

无论如何,您的代码应该按原样工作......我只是避免声明变量并在按下“确定”或自行关闭的情况下拆分消息。

您使用 Excel 2007 吗?我听说它有这么奇怪的行为。如果是这种情况,您应该使用更复杂的方法来调用 API。我可以帮助一段代码。看起来 Tim Williams 指出了这样一个解决方案。

【讨论】:

    猜你喜欢
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多