Wednesday, April 7, 2010

Creating Pop Up Alerts

Typically, msgbox's in Excel stay within the excel window.
What you COULD create a vbscript that issues the msgbox or popup.
One nice thing about VBScript, is that it allows for a TIMED popup.
which means that you aren't going to have 10 waiting for you if you go to get a cup of coffee!
the vbscript could look something as simple as:
'----------- --------- --------- --------- --------- --------- --
'File: C:\temp\Popup. vbs
Sub Main
if (wscript.arguments. count > 0) then
msgbox wscript.arguments( 0)
end if
End Sub
Main
'----------- --------- --------- --------- --------- --------- --
or a little more complex:
'----------- --------- --------- --------- --------- --------- --
'File: C:\temp\Popup. vbs
Option Explicit
dim Wshshell
Sub Main
dim PopupTime, PopupTitle,BtnCode, msg, argcnt
PopupTime = 3
PopupTitle = "Status"
Set WshShell = WScript.CreateObjec t("WScript. Shell")
argcnt = wscript.arguments. count
if (argcnt > 0)then
msg = wscript.arguments( 0)
BtnCode = WshShell.Popup( msg, PopupTime, PopupTitle, 1 + 32)
end if
End Sub
Main
'----------- --------- --------- --------- --------- --------- --
then your VBA code would look something like:
Sub testpopup()
Dim stat, msg, cmd
msg = "This is a test"
cmd = "C:\WINNT\system32\ wscript.exe ""C:\temp\Popup. vbs"" """ & msg & """"
stat = Shell(cmd, vbNormalFocus)
End Sub
this should force the popup to appear at any time.
hope this helps.

No comments:

Search This Blog

ShareThis