Timeout Msgbox popup
30,857
The Popup()
method of the WShell
object can timeout after a specified number of seconds. Here's an example that should disappear after 30 minutes.
CreateObject("WScript.Shell").Popup "Hello!", 1800, "Title"
Author by
Gavin
Updated on July 05, 2022Comments
-
Gavin almost 2 years
I have a small script that runs (basically fires a msgbox to tell people that their account passwords are about to expire).
I want it to close itself after say 30 minutes, but cannot get the syntax right to do it, can anyone help?
Below is the section that calls the msgbox
if (daysLeft < warningDays) and (daysLeft > -1) then Msgbox "Your Password Expires in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "Please ensure that you change your password before" & chr(13) & "its expiry time to prevent any disruption of service.", 4144, "PASSWORD EXPIRATION WARNING!" End if
--
Gavin.
-
Gavin about 10 yearsThis article suggests it is possible: autohotkey.free.fr/docs/commands/MsgBox.htm
-
AWS Cloud Architect Rob about 10 yearsI don't know what that relates to, but i have not seen a timeout facility on the msgbox before see link or MSDN microsoft official webpage [link] (msdn.microsoft.com/en-us/library/sfw6660x(v=vs.84).aspx)
-
AWS Cloud Architect Rob about 10 yearsthe link you have sent is from AutoHotKey which is a custom scripting language and so is not vbscript, but very similar syntax to it. As mentioned i think you will need a HTA application to create what you need
-
Miguel Rubio over 6 yearsWorks really good,just remember that the time set as 1800 is in seconds.
-
Ben almost 5 yearsIs there a way to make this popup SystemModal or a way to keep it on top of other windows?
-
Ben almost 5 yearsAdd
,4096
to the end of the command to open as a system modal message box that appears in a top most window. -
Ben almost 5 yearsNote that the timeout works in vbscript but not in Office VBA. If you want to use it in Office VBA, try this method that uses mshta.exe: stackoverflow.com/a/44837192/1898524
-
Ben almost 5 yearsI'm not the only one having issues with in Office VBA. Discussion and an alternative using mshta.exe are shown here. Note that the mshta method does not support carriage returns and always shows the message on the primary monitor. This link shows a API MsgBox that supports timeout, carriage returns, and return values. @Bond, your answer here was an inspiration for me. I've been using VBA 20 years and never knew a timeout was possible until this week.