0

I am trying the WScript.Shell script in VBA. The problem is that the window opens but does not close at the end of time. I think it has something to do with "enabling" VBScript.

My code:

Sub Teste1()
Dim i As Integer

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

I found this post, I run code but the problem is the same, open window but does not close at the end of time. https://learn.microsoft.com/en-us/office/vba/excel/concepts/controls-dialogboxes-forms/automatically-dismiss-a-message-box

ouflak
  • 2,458
  • 10
  • 44
  • 49

1 Answers1

0

I did not have any problems with your code, bat I red that this could be a bug in some MS Office application, see this post.

The other option, which worked for me, is run a vbscript call to Shell.Popup with mshta.exe:

Function Test()

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

End Function

pizzettix
  • 411
  • 2
  • 9