VBA 自动关闭消息框 - 不关闭?

问题描述

我正在 VBA 中尝试 WScript.Shell 脚本。问题是窗口打开但在时间结束时没有关闭。 我认为这与“启用”VBScript 有关。

我的代码

Sub Teste1()
Dim i As Integer

    i = CreateObject("WScript.Shell").Popup("Upper Sample text",1,"Text 2",0)
End Sub

我找到了这篇文章,我运行代码但问题是一样的,打开窗口但在时间结束时没有关闭https://docs.microsoft.com/en-us/office/vba/excel/concepts/controls-dialogboxes-forms/automatically-dismiss-a-message-box

解决方法

我对您的代码没有任何问题,我认为这可能是某些 MS Office 应用程序中的错误,请参阅此 post

另一个对我有用的选项是使用 mshta.exe 运行对 Shell.Popup 的 vbscript 调用:

Function Test()

    Dim Shell
    Set Shell = CreateObject("WScript.Shell")
    Shell.Run "mshta.exe vbscript:close(CreateObject(""WScript.shell"").Popup(""Test"",3,""Message""))"

End Function