In the following code I'm always getting a runtime error in the label file2 when it doesn't exist. As I've handled the exception it should technically proceed forward. When file1 doesn't exist, it's exception is always handled but an error always pops up in the file2 part.
Code:
Sub testing()
On Error GoTo file2
Workbooks.Open Filename:="C:Excels\file1.csv"
Windows("file1.csv").Activate
Columns("A:A").Select
Range("A1:A5000").Select
Selection.Copy
Windows("Basesheet.xlsm").Activate
Sheets("file1").Select
Range("A1").Select
ActiveSheet.Paste
Windows("file1.csv").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
file2:
On Error GoTo file3
Workbooks.Open Filename:="C:Excels\file2.csv"
Windows("file2.csv").Activate
Columns("A:A").Select
Range("A1:A5000").Select
Selection.Copy
Windows("Basesheet.xlsm").Activate
Sheets("file2").Select
Range("A1").Select
ActiveSheet.Paste
Windows("file2.csv").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
file3:
On Error GoTo file4
Workbooks.Open Filename:="C:Excels\file3.csv"
Windows("file3.csv").Activate
Columns("A:A").Select
Range("A1:A5000").Select
Selection.Copy
Windows("Basesheet.xlsm").Activate
Sheets("file3").Select
Range("A1").Select
ActiveSheet.Paste
Windows("file3.csv").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
file4:
On Error GoTo file5
Workbooks.Open Filename:="C:Excels\file4.csv"
Windows("file4.csv").Activate
Columns("A:A").Select
Range("A1:A5000").Select
Selection.Copy
Windows("Basesheet.xlsm").Activate
Sheets("file4").Select
Range("A1").Select
ActiveSheet.Paste
Windows("file4.csv").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
file5:
On Error GoTo exi
Workbooks.Open Filename:="C:Excels\file5.csv"
Windows("file5.csv").Activate
Columns("A:A").Select
Range("A1:A5000").Select
Selection.Copy
Windows("Basesheet.xlsm").Activate
Sheets("file5").Select
Range("A1").Select
ActiveSheet.Paste
Windows("file5.csv").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
exi:
Exit Sub
End Sub