hellfire45
Active Member
- Joined
- Jun 7, 2014
- Messages
- 464
I highlighted the row that is giving me the error. This file I am opening (docsource1), sometimes it has a specific worksheet, "Regions Messages", and sometimes it doesnt. I need some kind of error handler so that when the sheet DOESN'T exist, It will skip that section with regions messages and move on with the rest of the program.
Any suggestions on how I can write that into the code? Thank you so much!
Any suggestions on how I can write that into the code? Thank you so much!
Code:
If Dir(filepath1 & docname1) <> "" Then
docsource1 = "VS_Workload-" & Format(Date, "yyyy-mm-dd") & ".xls"
ElseIf Dir(filepath1 & docname1a) <> "" Then
docsource1 = "VS_Workload-" & Format(Date - 1, "yyyy-mm-dd") & ".xls"
ElseIf Dir(filepath1 & docname1b) <> "" Then
docsource1 = "VS_Workload-" & Format(Date - 2, "yyyy-mm-dd") & ".xls"
ElseIf Dir(filepath1 & docname1c) <> "" Then
docsource1 = "VS_Workload-" & Format(Date - 3, "yyyy-mm-dd") & ".xls"
ElseIf Dir(filepath1 & docname1d) <> "" Then
docsource1 = "VS_Workload-" & Format(Date - 4, "yyyy-mm-dd") & ".xls"
End If
Workbooks.Open filepath1 & docsource1, ReadOnly:=True
[B]Workbooks(docsource1).Worksheets("Regions Messages").Activate[/B]Workbooks(docsource1).Worksheets("Regions Messages").Range("A2:M2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ThisWorkbook.Sheets("RegionsMessages").Cells(1, 1).SpecialCells(xlCellTypeVisible).PasteSpecial xlValues
ThisWorkbook.Sheets("RegionsMessages").Activate
ActiveSheet.Calculate
'this dumps the information that is stored in the "copy"
Application.CutCopyMode = False
'closes the document with the variable name docname
Workbooks(docsource1).Close False
'makes sure that no display alert popups occur
Application.DisplayAlerts = False