I have the below code that I am trying to run. I am compiling data for all employees on my team for 2010. Some people didn't join the team until part way through the year and some people left before the year was over. What I want my code to do is look through the open workbooks, find the first sequential month that is open, run my other macro, close the workbook without saving and then move on to the next month. The workbooks I have open are August through December. When I run the macro, it sees that I don't have January open so it skips to February but then errors out on the highlighted line instead of skipping to March. Does anyone know why and either how to fix this or make it better? The workbook names are the same as in the macro so it's not a filename issue. Thanks in advance!
Sub Macro5()
'
' Macro5 Macro
'
' Keyboard Shortcut: Ctrl+i
'
On Error GoTo Feb:
Windows("January Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("January Tracker.xlsx").Close False
Feb:
On Error GoTo Mar:
Windows("February Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("February Tracker.xlsx").Close False
Mar:
On Error GoTo Apr:
Windows("March Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("March Tracker.xlsx").Close False
Apr:
On Error GoTo May:
Windows("April Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("April Tracker.xlsx").Close False
May:
On Error GoTo Jun:
Windows("May Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("May Tracker.xlsx").Close False
Jun:
On Error GoTo Jul:
Windows("June Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("June Tracker.xlsx").Close False
Jul:
On Error GoTo Aug:
Windows("July Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("July Tracker.xlsx").Close False
Aug:
On Error GoTo Sep:
Windows("August Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("August Tracker.xlsx").Close False
Sep:
On Error GoTo Oct:
Windows("September Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("September Tracker.xlsx").Close False
Oct:
On Error GoTo Nov:
Windows("October Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("October Tracker.xlsx").Close False
Nov:
Windows("November Tracker.xlsx").Activate
On Error GoTo Dec:
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("November Tracker.xlsx").Close False
Dec:
On Error GoTo LastErr:
Windows("December Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("December Tracker.xlsx").Close False
LastErr:
End Sub
Sub Macro5()
'
' Macro5 Macro
'
' Keyboard Shortcut: Ctrl+i
'
On Error GoTo Feb:
Windows("January Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("January Tracker.xlsx").Close False
Feb:
On Error GoTo Mar:
Windows("February Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("February Tracker.xlsx").Close False
Mar:
On Error GoTo Apr:
Windows("March Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("March Tracker.xlsx").Close False
Apr:
On Error GoTo May:
Windows("April Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("April Tracker.xlsx").Close False
May:
On Error GoTo Jun:
Windows("May Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("May Tracker.xlsx").Close False
Jun:
On Error GoTo Jul:
Windows("June Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("June Tracker.xlsx").Close False
Jul:
On Error GoTo Aug:
Windows("July Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("July Tracker.xlsx").Close False
Aug:
On Error GoTo Sep:
Windows("August Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("August Tracker.xlsx").Close False
Sep:
On Error GoTo Oct:
Windows("September Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("September Tracker.xlsx").Close False
Oct:
On Error GoTo Nov:
Windows("October Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("October Tracker.xlsx").Close False
Nov:
Windows("November Tracker.xlsx").Activate
On Error GoTo Dec:
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("November Tracker.xlsx").Close False
Dec:
On Error GoTo LastErr:
Windows("December Tracker.xlsx").Activate
Application.Run "PERSONAL.XLSB!Macro4"
Workbooks("December Tracker.xlsx").Close False
LastErr:
End Sub