Run Time macro based on the value in cell

E

Elton Law

Dear Expert,
Currently, I am running a time macro ...
I have to change the time in VB script.
Is it pssible for me to set the time in cell E2 and then run the time maco
based on the value in cell E2 ? Thanks


Sub StartTimer()

CreateObject("WScript.Shell").Popup "Macro is going to run on scheduled
time.", 2, "Thank you very much for your cooperation"
RunWhen = TimeSerial(3, 30, 0)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
 
J

JLGWhiz

Try this:

Sub StartTimer()

CreateObject("WScript.Shell").Popup "Macro is going to run on scheduled
time.", 2, "Thank you very much for your cooperation"
RunWhen = TimeValue(Range("A1").Value) '<<Range to use???
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
 
E

Elton Law

Hi Friend,

Error message comes on this script ....
It turns yellow ....
RunWhen = TimeValue(Range("E2").Value)
Can you help again ? Thanks
Elton
 
J

JLGWhiz

Format cell E2 as text.
Sub test()
Range("E2").NumberFormat = "@"
CreateObject("WScript.Shell").Popup "Macro is going to run on scheduled
time.", 2, "Thank you very much for your cooperation"
RunWhen = TimeValue(Range("A1").Value) '<<Range to use???
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
 
E

Elton Law

Wonderful !!!! Make it ... Thanks so much !

JLGWhiz said:
Format cell E2 as text.
Sub test()
Range("E2").NumberFormat = "@"
CreateObject("WScript.Shell").Popup "Macro is going to run on scheduled
time.", 2, "Thank you very much for your cooperation"
RunWhen = TimeValue(Range("A1").Value) '<<Range to use???
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
 

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

Top