I have bunch of excel files of which some contain P3 sheets, some P2, and very few neither. I tried to use error handling, but if two files in a row do not have P3. I had an error within an error block. So I tried to end the error block with resume next or something. But then I would go back to just after the error. Whilst I actually wanted to continue after the error handling block (without ending the code). Any suggestions? Or would it be better to use a different method to identify the existence of the sheet?
Do While myFile <> ""
Set wbCase = Workbooks.Open(Filename:=myPath & myFile, UpdateLinks:=0)
On Error GoTo Line2
Set wsCaseinfo = wbC.Worksheets("P3")
GoTo Line3:
Line2:
On Error GoTo Line0
Set wsCaseinfo = wbC.Worksheets("P2")
Resume Next
Line3:
On Error GoTo 0
...
some code doing stuff
...
On Error Resume Next
k = k + 1
wbNew.Sheets("Sheet1").Cells(k, 1) = wbC.Name
wbNew.Sheets("Sheet1").Cells(k, 2) = wsCinfo.Name
GoTo Line1
Line0:
wbNew.Sheets("Sheet1").Cells(k, 3) = "Fail"
Resume Next
Line1:
wbC.Close SaveChanges:=False
'Get next file name
myFile = Dir
Loop