RedOctoberKnight
Board Regular
- Joined
- Nov 16, 2015
- Messages
- 150
- Office Version
- 2016
- Platform
- Windows
Good Morning.
I have the following code that pulls a schedule from another workbook. However, if the schedule in the other workbook hasn't been created yet, I obviously get an error. I'm looking for some help on having a msgbox pop up that states something like "schedule not created yet" if the schedule cant be found. Any help would be much appreciated.
I have the following code that pulls a schedule from another workbook. However, if the schedule in the other workbook hasn't been created yet, I obviously get an error. I'm looking for some help on having a msgbox pop up that states something like "schedule not created yet" if the schedule cant be found. Any help would be much appreciated.
VBA Code:
Public Sub Copy_Range_From_Truck_Schedules()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim tsWorkbook As Workbook
Set tsWorkbook = Workbooks.Open(ThisWorkbook.Path & "\truckschedulesdualsides.xlsx")
With ThisWorkbook.ActiveSheet
.Range("A1:Q100").UnMerge
tsWorkbook.Worksheets(.Name).Range("A1:Q100").Copy
.Range("A1").PasteSpecial xlPasteValues
.Range("A1").PasteSpecial xlPasteFormats
.Range("A1").PasteSpecial xlPasteColumnWidths
.Range("C:D").EntireColumn.AutoFit
.Range("F:H").EntireColumn.AutoFit
.Range("K:M").EntireColumn.AutoFit
.Range("O:Q").EntireColumn.AutoFit
.Range("N:N").EntireColumn.Hidden = True
End With
tsWorkbook.Close False
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub