Solved

Application On time Question

Posted on 2013-10-24
3
158 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 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now