How do you set up to handle an error within an error handler?
Here is what i want to do. I try this statement. If it works, i'm done.
Set wbDest = Workbooks(Dest)
If it fails I want to go to an error handler that tries to open the file:
Workbooks.Open Filename:=dir_loc & Dest
And if that fails, i want to go to an error handler that creates the workbook:
Workbooks.Add
...
I paste the entire code below.
What is happening is that if the attempt to open the workbook errors, the VBA sub fails, and the ON ERROR GOTO just before that statement seems to be ignored.
How is this case property set up to work?
Sub Init_Books()
Src = "D4_p_TRK.xlsm"
Dest = "D4p_new4.xlsm"
Set wbSrc = Workbooks(Src)
On Error GoTo needopen
Set wbDest = Workbooks(Dest)
GoTo end_sub
needopen:
dir_loc = "C:\Users\xxxx\Documents\"
On Error GoTo create_it
ChDir dir_loc
Workbooks.Open Filename:=dir_loc & Dest 'Why does this not get handled by the "On Error GOTO create_it" statement?
Resume
create_it:
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=dest_loc & Dest _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Resume
end_sub:
End Sub
Here is what i want to do. I try this statement. If it works, i'm done.
Set wbDest = Workbooks(Dest)
If it fails I want to go to an error handler that tries to open the file:
Workbooks.Open Filename:=dir_loc & Dest
And if that fails, i want to go to an error handler that creates the workbook:
Workbooks.Add
...
I paste the entire code below.
What is happening is that if the attempt to open the workbook errors, the VBA sub fails, and the ON ERROR GOTO just before that statement seems to be ignored.
How is this case property set up to work?
Sub Init_Books()
Src = "D4_p_TRK.xlsm"
Dest = "D4p_new4.xlsm"
Set wbSrc = Workbooks(Src)
On Error GoTo needopen
Set wbDest = Workbooks(Dest)
GoTo end_sub
needopen:
dir_loc = "C:\Users\xxxx\Documents\"
On Error GoTo create_it
ChDir dir_loc
Workbooks.Open Filename:=dir_loc & Dest 'Why does this not get handled by the "On Error GOTO create_it" statement?
Resume
create_it:
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=dest_loc & Dest _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Resume
end_sub:
End Sub