How to automatically run a macro at a specific time?

G

Guest

Guest
I want to run a macro at a user specified time. I tried defining a variable as =NOW() and then setting up ado loop statement to say that if the variable equals the user defined time, then run the macro but that jsut seemed to crash my computer.
Any ideas?

Regards
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I use something like this:

Public RunWhen As Double
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Range("c3")
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub

Sub The_Sub()
MsgBox ("Does this Work?")
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:=cRunWhat, schedule:=False
End Sub


Then I set up range("c3") to equal something like:

3/4/2002 10:08:00 AM

Start the process by simply running "Sub StartTimer()".

But I would set the timedate for sometime in the future, versus now. "Sub The_Sub()" is your procedure to run at the given time.

Hope this helps. Cheers,

Nate
This message was edited by NateO on 2002-03-04 08:16
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,386
Members
448,891
Latest member
tpierce

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