VBA: Message Box pop up at end of timer ???

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
831
Office Version
  1. 365
Platform
  1. Windows
The code below is what I use to shut excel down at a certain time.
I would like to have some code that at say 3:30pm a message box will pop up that says "Send Form Before your shift ends"

Thanks as Always

Code:
Sub RunOnTime()
dTime = TimeSerial(16, 31, 2)
Application.OnTime dTime, "QuitExcel"
End Sub
Sub QuitExcel()
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.Quit
End Sub
Sub CancelOnTime()
Application.OnTime dTime, "RunOnTime", , False
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
It didnt change anything >> It still does nothing when time comes around

I told you you should change two lines

try this code


Code:
Sub ShowMsg() 
If TimeValue(Now()) > TimeValue("3:30:00 am") Then 
Exit Sub 
End If 
Application.OnTime Now + TimeValue("00:00:01"), "TimedMsgBox" 
End Sub  

Sub TimedMsgBox() 
If TimeValue(Now()) = TimeValue("3:30:00 am") Then 
MsgBox "Send Form Before your shift ends" 
End If 
ShowMsg 
End Sub
 
Upvote 0
I wish I new more about VBA. one more question. Can the be modified to pop up the message a 2 different times??? Say 4:50 PM and then again at 9:00 PM
 
Upvote 0
I wish I new more about VBA. one more question. Can the be modified to pop up the message a 2 different times??? Say 4:50 PM and then again at 9:00 PM

sure try this

Code:
Sub ShowMsg()
If TimeValue(Now()) > TimeValue("9:10:00 pm") Then
Exit Sub
End If
Application.OnTime Now + TimeValue("00:00:01"), "TimedMsgBox"
End Sub

Sub TimedMsgBox()
If TimeValue(Now()) = TimeValue("4:50:00 pm") Then
MsgBox "Send Form Before your shift ends pt1"
End If
If TimeValue(Now()) = TimeValue("9:00:00 pm") Then
MsgBox "Send Form Before your shift ends pt2"
End If
ShowMsg
End Sub
 
Upvote 0
I wish I new more about VBA. one more question. Can the be modified to pop up the message a 2 different times??? Say 4:50 PM and then again at 9:00 PM

sure try this

Code:
Sub ShowMsg()
If TimeValue(Now()) > TimeValue("9:10:00 pm") Then
Exit Sub
End If
Application.OnTime Now + TimeValue("00:00:01"), "TimedMsgBox"
End Sub

Sub TimedMsgBox()
If TimeValue(Now()) = TimeValue("4:50:00 pm") Then
MsgBox "Send Form Before your shift ends pt1"
End If
If TimeValue(Now()) = TimeValue("9:00:00 pm") Then
MsgBox "Send Form Before your shift ends pt2"
End If
ShowMsg
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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