ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   On time Event (https://www.excelbanter.com/excel-programming/299830-time-event.html)

ExcelMonkey[_127_]

On time Event
 
I am trying to program an alarm like this:

Sub SetAlarm()
Application.OnTime TimeValue("12:12:00 pm"), "DisplayAlarm"
End Sub

Sub DisplayAlarm()
Beep
MsgBox "Wake up. Its time for your afternoon break!"

End Sub

However it never seems to go off. I have put in a regular module.
What have I done wrong?

Thank-yo

--
Message posted from http://www.ExcelForum.com


pikus

On time Event
 
In order for the application to check the time SetAlarm() has to b
running. If you start SetAlarm() you can have it WAIT until that time
but that probably won't work for you. Search the newsgroup and yo
should find several explanations of how to do exactly what you'r
asking about. - Piku

--
Message posted from http://www.ExcelForum.com


Charles

On time Event
 
ExcelM,

Here is another example and it works.

Sub SetAlarm()
Application.OnTime Now + TimeValue("00:01:00"), "DisplayAlarm"
End Sub

Sub DisplayAlarm()
Beep
MsgBox "Wake up. Its time for your afternoon break!"

End Sub


Charle

--
Message posted from http://www.ExcelForum.com


ExcelMonkey[_128_]

On time Event
 
The reason it wasn't working is that I did not run it. I forgot it wa
in a module which actually needs to RUN. I was sitting there waitin
for it to engage like a dummay!!!!!

Yes Charles yours works too WHEN RUN.

Thanks

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

On time Event
 
SetAlarm doesn't have to be running for this to work. It has to have been
run one time to set the event.

Sub SetAlarm()
Application.OnTime TimeValue("2:43:00 pm"), "DisplayAlarm"
End Sub

Sub DisplayAlarm()
Beep
MsgBox "Wake up. Its time for your afternoon break!"

End Sub

worked fine for me.

If Excel had the focus the message pop'd up in the foreground

If Excel did not have the focus, the Excel icon on the taskbar turned blue
and pulsed. Activating excel revealed the message pop'd up.

Excel 2000, Windows 2000

--
Regards,
Tom Ogilvy

"pikus " wrote in message
...
In order for the application to check the time SetAlarm() has to be
running. If you start SetAlarm() you can have it WAIT until that time,
but that probably won't work for you. Search the newsgroup and you
should find several explanations of how to do exactly what you're
asking about. - Pikus


---
Message posted from http://www.ExcelForum.com/




ExcelMonkey[_129_]

On time Event
 
Another question. What if I wanted this to run every minute. The cod
below when ran will excute once i.e. 1 minute after NOW. However i
does not run again. In order to dot this, do I have to make th
SetAlarm sub call itself befor the EndSub line (i.e. recursiv
programming)?

Thanks



Sub SetAlarm()
Application.OnTime Now + TimeValue("00:01:00"), "DisplayAlarm"
End Sub

Sub DisplayAlarm()
Beep
MsgBox "Wake up. Its time for your afternoon break!"

End Su

--
Message posted from http://www.ExcelForum.com


Chip Pearson

On time Event
 
See www.cpearson.com/excel/ontime.htm for example code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"ExcelMonkey " wrote
in message ...
Another question. What if I wanted this to run every minute.

The code
below when ran will excute once i.e. 1 minute after NOW.

However it
does not run again. In order to dot this, do I have to make

the
SetAlarm sub call itself befor the EndSub line (i.e. recursive
programming)?

Thanks



Sub SetAlarm()
Application.OnTime Now + TimeValue("00:01:00"), "DisplayAlarm"
End Sub

Sub DisplayAlarm()
Beep
MsgBox "Wake up. Its time for your afternoon break!"

End Sub


---
Message posted from http://www.ExcelForum.com/




ExcelMonkey[_130_]

On time Event
 
So Chip, I used teh following code from your site. But it only ran onc
as opposed to every minute.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60 ' one minute
Public Const cRunWhat = "The_Sub"

Sub StartTimer()

RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=True
End Sub

Sub The_Sub()
MsgBox "Wake up. Its time for your afternoon break!"
End Su

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

On time Event
 
Public RunWhen As Double
Public Const cRunIntervalSeconds = 60 ' one minute
Public Const cRunWhat = "The_Sub"

Sub StartTimer()

RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=True
End Sub

Sub The_Sub()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=True
MsgBox "Wake up. Its time for your afternoon break!"
End Sub

Sub StopIt()
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=False
End Sub

--
Regards,
Tom Ogilvy


"ExcelMonkey " wrote in message
...
So Chip, I used teh following code from your site. But it only ran once
as opposed to every minute.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60 ' one minute
Public Const cRunWhat = "The_Sub"

Sub StartTimer()

RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=True
End Sub

Sub The_Sub()
MsgBox "Wake up. Its time for your afternoon break!"
End Sub


---
Message posted from http://www.ExcelForum.com/




Chip Pearson

On time Event
 
You need to set RunWhen and then call OnTime from within The_Sub.


"ExcelMonkey " wrote
in message ...
So Chip, I used teh following code from your site. But it only

ran once
as opposed to every minute.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60 ' one minute
Public Const cRunWhat = "The_Sub"

Sub StartTimer()

RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,

_
schedule:=True
End Sub

Sub The_Sub()
MsgBox "Wake up. Its time for your afternoon break!"
End Sub


---
Message posted from http://www.ExcelForum.com/




ExcelMonkey[_131_]

On time Event
 
thanks Tom. I guess I could call the StartTimer sub again at the end o
the final sum too.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 60 ' one minute
Public Const cRunWhat = "The_Sub"

Sub StartTimer()

RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=True
End Sub

Sub The_Sub()
MsgBox "Wake up. Its time for your afternoon break!"
StartTimer
End Su

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 01:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com