Automatically close MsgBox in vbscript?
Asked Answered
H

2

4

I am using VBScript to code some automation on excel. I have a MsgBox() within the code, and am looking for a way to close the pop-up window created by MsgBox() automatically without human intervention. Program execution would continue from there.

Headless answered 31/12, 2012 at 18:51 Comment(3)
Did you change your name again Tukai? OMG! Well what you need can be done! ;) It's called a MSGBOX timer which gets triggered after being idle....Strafe
@Strafe But how to do that?Headless
Here's a very similar question I answered yesterday #14096482Pyroxene
S
4

My comment has provided you tips to search and find out feasible answers. However to save your time, here is some insights.

  • This post shows how you may manupulate MSGBOX in VB.

  • Here is the best possible way anyone could think of in terms of VBA.

    1. Create a form
    2. Use it as a MSGBOX
    3. Add a timer
    4. Given an elapsed time (idle) close the form.

--

  • Another method Reference. This uses a Pop-Up box as the MSGBOX.

Code:

Sub Test1()
 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
End Sub
Strafe answered 31/12, 2012 at 19:7 Comment(4)
any other way to close pop-up window generated by MsgBox?Headless
@Tukai do check on the updated I made on the answer. It seems to be pretty well for you since you are working on VBScript. Try that and comment please.Strafe
yes i m trying,but meanwhile could you say what 0 does here ?Headless
Here is the syntax. Please read on.Strafe
I
6

The pure VBScript solution is the .PopUp method.

Iwo answered 31/12, 2012 at 20:20 Comment(4)
+1, definitely ideal. I've used this before from VBA for the same reason.Pyroxene
@Ekkehard you are gr8 as usual!!Headless
@Ekkehard can I have some help here - #14088181?Headless
To make this answer stand alone and be more complete, please edit it to contain a brief example right here too.Woebegone
S
4

My comment has provided you tips to search and find out feasible answers. However to save your time, here is some insights.

  • This post shows how you may manupulate MSGBOX in VB.

  • Here is the best possible way anyone could think of in terms of VBA.

    1. Create a form
    2. Use it as a MSGBOX
    3. Add a timer
    4. Given an elapsed time (idle) close the form.

--

  • Another method Reference. This uses a Pop-Up box as the MSGBOX.

Code:

Sub Test1()
 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
End Sub
Strafe answered 31/12, 2012 at 19:7 Comment(4)
any other way to close pop-up window generated by MsgBox?Headless
@Tukai do check on the updated I made on the answer. It seems to be pretty well for you since you are working on VBScript. Try that and comment please.Strafe
yes i m trying,but meanwhile could you say what 0 does here ?Headless
Here is the syntax. Please read on.Strafe

© 2022 - 2024 — McMap. All rights reserved.