Code to Run macro on specific date

djossh

Board Regular
Joined
Jul 27, 2009
Messages
243
Please help, i need a code to run macro on specific date.

ex. i want my macro to run on January 30, 2011 at 1:30pm (i want it to run automatically after i open the workbook) thanks..
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Enter this code in thisworkbook module

Rich (BB code):
Private Sub Workbook_Open()
Application.OnTime TimeValue("13:30:00"), "MyMacro"
'here mymacro stands for macro name you want to run when the time comes
End Sub
 
Upvote 0
this code will run on JANUARY 30, 2011 at 1:30pm??.. it looks like this code will run at 1:30pm but not specifically on "January 30, 2011 @ 1:30pm"



Enter this code in thisworkbook module

Rich (BB code):
Private Sub Workbook_Open()
Application.OnTime TimeValue("13:30:00"), "MyMacro"
'here mymacro stands for macro name you want to run when the time comes
End Sub
 
Upvote 0
Looks like pedie's code is more efficient, but this should work also in a longer way to do it:

If you have your date and time in cell A1 formatted as : 1/30/2011 13:30 then try this:

Code:
Sub Auto_Open() 'runs whenever workbook is opened
    Range("A2").Select
    ActiveCell.Value = "=now()" 
    If ActiveCell.Value > Range("A1").Value Then
        Application.Run "ExcelFileName!MyMacro"
    End If
End Sub
 
Upvote 0
I thought you can handle from there sorry...
then something like this...
Code:
[/FONT]
[FONT=Courier New]Private Sub Workbook_Open()[/FONT]
[FONT=Courier New]Application.OnTime TimeValue("13:30:00"), "MyMacro"[/FONT]
[FONT=Courier New]'here mymacro stands for macro name you want to run when the time comes[/FONT]
[FONT=Courier New]End Sub[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New][/FONT] 
[FONT=Courier New]sub MyMacro()[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New] if date <> "1/30/2011" then exit sub[/FONT]
[FONT=Courier New]'what you want goes here..[/FONT]
[FONT=Courier New]end sub[/FONT]
 
Upvote 0
Thanks Pedie.. thanks also chuckchuckit.. Pedie's code is what im really looking for.. I think putting date in a cell is not an option.. i might delete the date accidentally and for sure if its happened my macro wont work..thanks guys........

2 beers for both of you..thanks



I thought you can handle from there sorry...
then something like this...
Code:
[/FONT]
[FONT=Courier New]Private Sub Workbook_Open()[/FONT]
[FONT=Courier New]Application.OnTime TimeValue("13:30:00"), "MyMacro"[/FONT]
[FONT=Courier New]'here mymacro stands for macro name you want to run when the time comes[/FONT]
[FONT=Courier New]End Sub[/FONT]
 
 
[FONT=Courier New]sub MyMacro()[/FONT]
 
[FONT=Courier New]if date <> "1/30/2011" then exit sub[/FONT]
[FONT=Courier New]'what you want goes here..[/FONT]
[FONT=Courier New]end sub[/FONT][/QUOTE]
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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