Solved

Application On time Question

Posted on 2013-10-24
3
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

621 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