Run Macro at specified time

S

SANDIND

Hi

I want to run a macro at specified time suppose 2.30 pm.

I have two clarrification(featues) regarding this : (1) Can this timed macro
run even if the workbook is closed (2) Workbook is placed in share drive.

If someone can help me with the macro having both the features then I would
really apprecite his efforts.

Thanks, SS
 
M

Mike

It probably can with some complex coding. But I use Windows Task Scheduler
and it works Great !!!
 
S

SANDIND

HI Mike,

Thanks for your response, Can you please guide me through what you use.

What changes or addition I need to make to the code.
SS
 
M

Mike H

Hi,

This workbook open module

Private Sub Workbook_Open()
Application.OnTime TimeValue("14:30:00"), "MySub"
End Sub

and this in a standard module

Sub MySub()
Application.OnTime
TimeValue ("14:30:00"), "MyMacro"
'Do lots of things
End Sub

1. The workbook must be open for this to work so you can leave it open or
open it with Windows task scheduler.

2. AFAIK there are no issues with this on a shared drive.

Mike
 
S

SANDIND

Hi Mike H

Thanks a Lot !!

I am sorry I am knew to VB , Can you please tell me what do you mean by
Standard module, do I need to copy that in a new module.

And also can you please let me know that here :
TimeValue ("14:30:00"), "MyMacro"

In place of my macro, do I only need to type name of macro which I want to
run or the full code.

Thanks a lot for all your help.

SS
 
M

Mike H

Hi,

Alt +f11 to open VB editor. Double click 'This workbook' and past this in

Private Sub Workbook_Open()
Application.OnTime TimeValue("14:30:00"), "MySub"' Change to your sub name
End Sub

Now right click 'This Workbook' and 'Insert Module' and paste your sub in.
Note that the first 2 lines of your sub must be
Application.OnTime
TimeValue ("14:30:00"), "MySub" 'Change to your sub name


Sub MySub() 'Change to your sub name
Application.OnTime
TimeValue ("14:30:00"), "MySub" 'Change to your sub name
'Your code
End Sub


Mike
 
S

SANDIND

Thanks Mike H,

For detailed explanation.. I really appreciate your help and looking forward.

Regards, SS
 

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