Originally Posted by
shs91
Hi Paul
However, I think that solution is more complicated and less readable than mine.
I'll disagree, esp since
I have reports I run every day, and some I run on specify days, so there is no clear pattern
implies that "Productions_Reports" is only one of several / many that are run on various schedules
It appears to me that a better example would be something like
If Weekday(Now(), vbMonday) = 1 Or Weekday(Now(), vbMonday) = 3 Then Productions_Reports_1
If Weekday(Now(), vbMonday) = 2 Or Weekday(Now(), vbMonday) = 3 Then Inventory_Reports_2
If Weekday(Now(), vbMonday) = 4 Or Weekday(Now(), vbMonday) = 5 Then Sales_Reports_3
If Weekday(Now(), vbMonday) = 3 Or Weekday(Now(), vbMonday) = 6 Or Weekday(Now(), vbMonday) = 1 Or Weekday(Now(), vbMonday) = 4 Then Warehouse_Reports_4
etc
IN MY OPINION >>> I think that a bunch of IF's that that are more difficult to maintain and to read <<< IN MY OPINION
One way to use arrays
Option Explicit
Sub UsingArray()
Dim aReports(vbSunday To vbSaturday)
Dim v As Variant
aReports(vbMonday) = Array("Report1", "Report2")
aReports(vbTuesday) = Array("Report1", "Report3")
aReports(vbWednesday) = Array("Report2", "Report3")
'etc
For Each v In aReports(Weekday(Now))
Application.Run v
Next
End Sub
Sub Report1()
MsgBox "Report 1"
End Sub
Sub Report2()
MsgBox "Report 2"
End Sub
Sub Report3()
MsgBox "Report 3"
End Sub
Sub Report4()
MsgBox "Report 4"
End Sub
Sub Report5()
MsgBox "Report 5"
End Sub