I would like to apply "On Error GoTo err1" only for the next few lines in the code:
On Error GoTo err1
ActiveWorkbook.SaveAs Filename:="C:\project\" & Year(Date) & "\" & _
MonthName(Month(Date)) & "\" & MyFileName & ".xls"
ActiveWorkbook.Close SaveChanges:=False
That's it, after that I want to disable error handling. I tried to add "On Error resume" but no results whatsoever. err1 handling looks like this:
err1:
MsgBox ("Project will not overwrite the file"), vbCritical
ActiveWorkbook.Close SaveChanges:=False
This sub saves one sheet of the file into new .xls file, it is automatically saved by date. In case there is already a file generated, and a person which will run the macro clicks on "No" when asked to overwrite the file, this err1
will pop out the message and will prevent user from getting debug message. However, this error handling seems to be going through all the code which is not good - after saving the file sub is generating an auto email, and if the person wants to go back to the project before clicking the "send" button it goes to the same err1
and closes the original workbook (not separate sheet that happens the first time) and leaves the user speechless. I want to avoid such situations as users with bad Excel skills will make these reports.
Any suggestions?
On Error Goto xxx
handler you can turn it off withOn Error Goto 0
Better yet, useDir()
to check for the existence of the file before calling the SaveAs operation. – Tim WilliamsOn Error Goto 0
, it will not re-call the handler. Did you place or error handlers correctly? See my post. – L42On Error Goto 0
would not cancel your current error handler, as @L42 shows in the answer below. I'm not clear what you're really asking, so it would help to include more relevant code if L42 hasn't already cleared up all of your concerns. – Tim Williams