main workbook : Including this macro
WB1 and WB1A-actual schedule : ?
WB2=Sched + Pickups Week 1 : this week
WB3=Sched + Pickups : the next weeks
I'm not quite sure what you want to do, but do you want to open WB2 or WB3 in the main workbook's macro?
| Execution date | WB2 | WB3 |
|---|---|---|
| 2025/11/29(Sat) | 11.30.25.xlsm | 12.07.25.xlsm |
| 2025/11/30(Sun) | 12.07.25.xlsm | 12.14.25.xlsm |
| 2025/12/1 (Mon) | 12.07.25.xlsm | 12.14.25.xlsm |
| 2025/12/2 (Tue) | 12.07.25.xlsm | 12.14.25.xlsm |
| 2025/12/3 (Wed) | 12.07.25.xlsm | 12.14.25.xlsm |
| 2025/12/4 (Thu) | 12.07.25.xlsm | 12.14.25.xlsm |
| 2025/12/5 (Fri) | 12.07.25.xlsm | 12.14.25.xlsm |
| 2025/12/6 (Sat) | 12.07.25.xlsm | 12.14.25.xlsm |
| 2025/12/7 (Sun) | 12.14.25.xlsm | 12.21.25.xlsm |
| 2025/12/8 (Mon) | 12.14.25.xlsm | 12.21.25.xlsm |
What if strgen is passed the number of weeks as an argument?
Function strgen(weeks As Long)
' weeks 1 : this weekend(Sunday) Sunday-Saturday next Sunday
' 2 : next weekend(Sunday)
strgen = Format(Date - Weekday(Now(), 1) + 1 + (weeks * 7), "mm.dd.yy") & ".xlsm"
End Function
How about doing it as follows in the macro you run?
Sub test()
Dim strDirPath As String
Dim strFilename1 As String
Dim strPath1 As String
Dim strFilename2 As String
Dim strPath2 As String
Dim strFilename As String
Dim strPath As String
Dim result As VbMsgBoxResult
strDirPath = "C:\Temp\Orginal Schedules\"
strFilename1 = "SCHED " & strgen(1)
strPath1 = strDirPath & strFilename1
strFilename2 = "SCHED " & strgen(2)
strPath2 = strDirPath & strFilename2
If Dir(strPath1) <> "" Then
If Dir(strPath2) <> "" Then
Select Case Weekday(Now(), 1)
Case 1 To 3
strFilename = strFilename1
Case 4
result = MsgBox("It is Wednesday. Do you want to open """ & strFilename1 & """", vbYesNo + vbQuestion, "Confirmation")
If result = vbYes Then
strFilename = strFilename1
Else
strFilename = strFilename2
End If
Case Else
strFilename = strFilename2
End Select
Else
strFilename = strFilename1
End If
ElseIf Dir(strPath1) <> "" Then
strFilename = strFilename2
Else
MsgBox "file does not exist.", vbOKOnly + vbCritical
Exit Sub
End If
strPath = strDirPath & strFilename
Workbooks.Open Filename:=strPath
Windows(strFilename).Activate
End Sub