Running Macro at a specified time

Kappy

Board Regular
Joined
Jun 26, 2009
Messages
58
I read the ozgrid article that everyone keeps citing, and I just can't seem to get it to work.

For a test, I wrote this:

Sub AutoRunTest()
Application.OnTime TimeValue("14:35:00"), "MyMacro"
End Sub

Sub MyMacro()
Workbooks("AutoRun Macro Test").Sheets(1).Range("D5") = Now()
End Sub

I tried writing the time in different formats (military, standard).. Just can't seem to figure out what I'm missing here..

can anyone help? Thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
If you need it to keep repeating

Code:
Sub AutoRunTest()
Application.OnTime TimeValue("14:35:00"), "MyMacro"
End Sub

Sub MyMacro()
Workbooks("AutoRun Macro Test").Sheets(1).Range("D5") = Now()
Application.OnTime TimeValue("14:35:00"), "MyMacro"
End Sub
 
Upvote 0
If you need it to keep repeating

Code:
Sub AutoRunTest()
Application.OnTime TimeValue("14:35:00"), "MyMacro"
End Sub

Sub MyMacro()
Workbooks("AutoRun Macro Test").Sheets(1).Range("D5") = Now()
Application.OnTime TimeValue("14:35:00"), "MyMacro"
End Sub

I'm not very good at excel, but I just had a question about this.
So wouldnt this slow down the sheet a lot because it would be repeating nonstop? Or how does it handle the code? Cause it seems to me it is just an infinite loop always running
 
Upvote 0
thanks vog,

but at this point, my concern isn't how to make it keep repeating (though that is helpful)... but rather, how to make it work at all!

to just tell excel a specific time, and have it execute a macro when that time occurs..

any ideas why my code isn't working?
 
Upvote 0
yes.

I ran the second macro on its own just to make sure I hadn't made a mistake with that one.. and it worked fine.

but I just can't seem to get it to run automatically at the indicated time

(thanks so much for trying to help me with this)
 
Upvote 0
At the risk of stating the obvious, you will have to wait until that time (your local time) is reached.
 
Upvote 0
As a work around, you can:
Write the macro so that it launches on workbook open
Then make a "scheduled task" that opens the workbook at a certain time.
 
Upvote 0
ha, yes... I waited for that time (and kept moving the time 5 minutes ahead when it didn't work so I could tweak the code and try again)

darkspartan, are you talking about using the windows scheduler?


in general, work around or not, its driving me nuts that I can't make this work. every google search eventually brings me back to the same code.. and it just won't work..

can you make that code work if you do it on your computer?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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