Put a timer on a MsgBox?

J

Joe 90

Is vba able to put a timer on a MSgBox, so that OK is "clicked" after a
specified time and a macro/code can continue?

I have tried allsorts but with Msgbox one seems to get complete freezing of
the app and vba.

Any help much appreciated.

Joe
 
B

Bob Phillips

Joe,

Use a custom form, and set the OnTime method when you initialise it to call
a proc that times out.

See OnTime in Help for details of that method.
 
J

Joe 90

Thanks Bob, I guess you have answered my question. I was trying to avoid
custom forms but if that's the only way to go, I'll go that way :)

Joe
 
C

Chip Pearson

Joe,

Set a reference to "Windows Script Host Object Model" and then use
code like

Dim SH As IWshRuntimeLibrary.WshShell
Set SH = New IWshRuntimeLibrary.WshShell
SH.Popup "Hello World", 5, "Title", vbYesNo

This will show a message box for 5 seconds, and then disappear,
returning the default value (Yes, in this example).


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
C

Chip Pearson

returning the default value (Yes, in this example).

Not correct. If the Popup times out with no user input, the
result is -1. Sorry for any confusion.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
J

Joe 90

Chip

Many thanks, I'll give it a whirl!

Joe

Chip Pearson said:
Not correct. If the Popup times out with no user input, the
result is -1. Sorry for any confusion.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
A

Alain CROS

Hi.

Try that.

Sub TimedMessage()
Const Title As String = "Self closing message box"
Const Delay As Byte = 2 ' Tps d'affichage en secondes
Const wButtons As Integer = 16 ' Boutons + icone
Dim wsh As Object, msg As String
Set wsh = CreateObject("WScript.Shell")
msg = Space(10) & "Bonjour," & vbLf & vbLf & "Nous sommes le " & Date
wsh.Popup msg, Delay, Title, wButtons
Set wsh = Nothing
End Sub

If you want no button
set Const wButtons As Integer = 7 + 16

Alain CROS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Self Closing MsgBox 6
linefeed in msgbox 2
Read MHT file using macro 0
WORD VBA Search and switch to advanced ... 1
How to stop 'Egg Timer' 3
Stopping a timer 10
Timer w/ Start, Stop, Pause 2
MsgBox problem 3

Top