Message disappearing automatically

Wil Moosa

Well-known Member
Joined
Aug 11, 2002
Messages
893
The following code shows after ten minutes -of use of the workbook- a message. When clicking the "OK" button the workbook will be closed.

I want to close the workbook automatically after ten seconds of showing the message. How can this be done?

Sub Timer_start()
Dim NextTime As Date
NextTime = Now + TimeValue("00:10:00")
Application.OnTime NextTime, "Message_before_Quit"
End Sub

Sub Message_Before_Quit()
MsgBox "Match Monitor will be closed within 10 seconds."
Application.run "Quit"
End Sub

Sub Quit()
Application.Quit
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Well, it ís what I'm after but as I came so far using a different road... the question still stands. Can a message be forced to run further code without using the key?
 
Upvote 0
How about this ? does not go automaticly but forces them to click "ok"

Sub Message_Before_Quit()
Dim Pause, Start, Mldg, Stil, Answer
Mldg = "Match Monitor will be closed within 10 seconds."
Stil = vbCritical + vbSystemModal
Answer = MsgBox(Mldg, Stil)
Pause = 10 ' pause how long.
Start = Timer
Do While Timer < Start + Pause
DoEvents ' lets uthere events run
Loop
Application.DisplayAlerts = False
Application.Quit
End Sub

just my humble effort
 
Upvote 0
Wil this seems to work if you put your warning message in a userform instead of a msgbox. Dave
Code:
Dim NextTime As Date
Sub Timer_start()
NextTime = Now + TimeValue("00:10:00")
Application.OnTime NextTime, "Message_before_Quit"
End Sub
Sub Message_Before_Quit()
Application.OnTime NextTime + TimeValue("00:00:10"), "Quit"
UserForm1.Show
End Sub
Sub Quit()
Application.DisplayAlerts = False
Unload UserForm1
ActiveWorkbook.Save
Application.Quit
Application.DisplayAlerts = True
End Sub
 
Upvote 0
How about this ?, has a OK button but you dont need to press it, closes automaticly after 10 sec.

Sub MsgBox10seconds()

Dim WsShell
Dim intText As Integer
Set WsShell = CreateObject("WScript.Shell")
intText = WsShell.Popup("Diese Meldung wird nach 3 Sekunden geschlossen.", 10, "Automatisch...")
Application.DisplayAlerts = False
Application.Quit
End Sub
 
Upvote 0
While both timers work well seperately... they do not work together. The second part of the code -from quit onwards is not executed.

Sub Timer_start()
Dim NextTime As Date
NextTime = Now + TimeValue("00:00:10")
Application.OnTime NextTime, "Quit"
End Sub

Sub Quit()
Dim WsShell
Dim intText As Integer
Set WsShell = CreateObject("WScript.Shell")
intText = WsShell.Popup("Diese Meldung wird nach 3 Sekunden geschlossen.", 10, "Automatisch...")
Application.DisplayAlerts = False
Application.Quit
End Sub

Even when I follow the suggestion to create a userform the second timer does not execute anything.

Suggestions? :pray:
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top