Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Application On time Question

Posted on 2013-10-24
3
Medium Priority
?
221 Views
Last Modified: 2013-10-27
How do I adapt the VBA code for Application.OnTime so it only run on Monday to Friday?

Sub Workbook_Open()

'Application.OnTime TimeSerial(8, 0, 0), "Macro5"    'Run the Import macro at 8 AM
Application.OnTime TimeValue("8:0:00"), "Macro5"
End Sub
0
Comment
Question by:Justincut
3 Comments
 
LVL 6

Expert Comment

by:Michael
ID: 39597189
Hi Justin,

maybe you can do it like this:

Sub Workbook_Open()
    'Application.OnTime TimeSerial(8, 0, 0), "Macro5"    'Run the Import macro at 8 AM
    Application.OnTime TimeValue("08:00:00"), "checkDay"
End Sub

Sub checkDay()
    If Weekday(Now(), vbMonday) > 5 Then
        Exit Sub
    Else
        Call Macro5
    End if
End Sub

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39597191
I suggest that you put a test at the start of Macro5

Sub Macro5()
Dim dow As Integer

dow = Format(Now, "w")
If dow = 1 Or dow = 7 Then
    Exit Sub
End If
'...

End Su

Open in new window

b
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 39597283
Depending on when you open the workbook, and what's in macro5, it may be simpler to just check before you schedule it:
Sub Workbook_Open()
    If Weekday(Date, vbmonday) < 6 then Application.OnTime TimeValue("08:00:00"), "Macro5"
End Sub

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question