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

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
826
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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
this should work

Copy these macros to a module


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

Sub TimedMsgBox()
If TimeValue(Now()) = "15:30:00" Then
MsgBox "Send Form Before your shift ends"
End If
ShowMsg
End Sub

In the WorkBook_Open event call the ShowMsg macro.
 
Upvote 0
this should work

Copy these macros to a module


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

Sub TimedMsgBox()
If TimeValue(Now()) = "15:30:00" Then
MsgBox "Send Form Before your shift ends"
End If
ShowMsg
End Sub

In the WorkBook_Open event call the ShowMsg macro.

This is not working in the open event
Code:
Private Sub Workbook_Open()
 Call ShowMsg
 End Sub
could you show me what im doing wrong ? It says Ambigious
I already have one in the open event, this is what it looks like
Code:
Private Sub Workbook_Open()
 Call RunOnTime
 End Sub
Private Sub Workbook_Open()
 Call ShowMsg
 End Sub
 
Upvote 0
I tried this in the open event
Code:
Private Sub Workbook_Open()
 Call RunOnTime
 Call ShowMsg
 End Sub
It didnt throw up am ambigious error, but it didnt work either ???????
 
Upvote 0
of course its not working i assume you have other reginal setting as we have in europe for this you have to change the timeformat from 15:30 to i guess 3:30pm or something like this

you can do a
Code:
debug.print time()
to see your timeformat my result would be 17:21:45 by now
 
Upvote 0
of course its not working i assume you have other reginal setting as we have in europe for this you have to change the timeformat from 15:30 to i guess 3:30pm or something like this

you can do a
Code:
debug.print time()
to see your timeformat my result would be 17:21:45 by now

I dont have a clue how to do this, this is what i tried but it does not work
Code:
Sub ShowMsg()
If TimeValue(Now()) > "09:57:00" Then
Exit Sub
End If
Application.OnTime Now + TimeValue "09:57:00" , "TimedMsgBox"
End Sub
Sub TimedMsgBox()
If TimeValue(Now()) = "09:57:00" Then
MsgBox "Send Form Before your shift ends"
End If
ShowMsg
End Sub
Also were do you put the AM or PM
 
Upvote 0
Im stumped. Ive put this in but when the time comes it does nothing>>>
I have this in This Workbook
Private Sub Workbook_Open()
Call RunOnTime
Call ShowMsg
End Sub

I have this in a module
Sub ShowMsg()
If TimeValue(Now()) > "08:24:10 AM" Then
Exit Sub
End If
Application.OnTime Now + TimeValue("00:00:01"), "TimedMsgBox"
End Sub
Sub TimedMsgBox()
If TimeValue(Now()) = "08:22:00 AM" Then
MsgBox "Send Form Before your shift ends"
End If
ShowMsg
End Sub
 
Upvote 0
in your code try with small am instead of AM

Code:
If TimeValue(Now()) > "08:24:10 [COLOR=#ff0000]am[/COLOR]" Then

Code:
If TimeValue(Now()) = "08:22:00 [COLOR=#ff0000]am[/COLOR]" Then

would this work?
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,843
Members
449,471
Latest member
lachbee

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