Application.OnTime TimeValue

Krikkers

New Member
Joined
Dec 14, 2015
Messages
5
Hello

I have written a macro for work that needs to execute every weekday.
It works well, but every time that I'm not in the office, it don't execute.
So for example if i'm off on Wednesday, Thursday morning it didn't run.
Also, I don't know how to include that it only runs on a weekday.
I have written this in ThisWorkbook:

Private Sub Workbook_Open()
Application.OnTime TimeValue("06:00:00"), "Macro"
End Sub

Someone that can help me?

Thanks a lot!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
On those days whether the file (system) will be running or turned off?
When I'm out of office on Wednesday, then the macro do run on Wednesday morning, but not on Thursday morning.
So it seems that it only runs once at 6 o'clock, except when I reopen Excel. Then the macro will run the next morning.
 
Upvote 0
If you want to leave the workbook unattended you will need to call the OnTime method again, at the end of your "Macro". Currently it's called only once when you open the workbook.
 
Upvote 0
In the end of Macro Code you have to reset the timer once again so that it will be kept on excel memory to trigger the code when the time hits.

Code:
Sub Macro()

    'Your code goes here
    Application.OnTime TimeValue("06:00:00"), "Macro"

End Sub
 
Upvote 0
In the end of Macro Code you have to reset the timer once again so that it will be kept on excel memory to trigger the code when the time hits.

Code:
Sub Macro()

    'Your code goes here
    Application.OnTime TimeValue("06:00:00"), "Macro"

End Sub
Thanks! I'll try that.
But how can I force that it only runs on weekdays?
 
Upvote 0
But how can I force that it only runs on weekdays?

Code:
Sub Macro()

Select Case Format(Date, "DDD")
    Case Is = "Mon", "Tue", "Wed", "Thu", "Fri"
        'Your Code Goes Here....
End Select

Application.OnTime TimeValue("06:00:00"), "Macro"

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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