I have the following VBA code in a before save event
' check if file exists. if yes save else saveas
Application.EnableEvents = False
If Len(Dir(FullName)) > 0 Then
ActiveWorkbook.Save
Else
ActiveWorkbook.SaveAs FileName:=FullName, AddToMru:=True
End If
Application.EnableEvents = True
End Sub
The code works fine, but after the execution, when excel should return to the spreadsheet I get an “Excel stopped working” and I have to restart excel and open the workbook again.
Any code I put in after SaveAs will be executed.
As you can see from the code, I have disabled events to avoid that excel will fire a new save event on the SaveAs and course a endless loop.
I have tried many things, but nothing works.
Any help will be much appreciated.
' check if file exists. if yes save else saveas
Application.EnableEvents = False
If Len(Dir(FullName)) > 0 Then
ActiveWorkbook.Save
Else
ActiveWorkbook.SaveAs FileName:=FullName, AddToMru:=True
End If
Application.EnableEvents = True
End Sub
The code works fine, but after the execution, when excel should return to the spreadsheet I get an “Excel stopped working” and I have to restart excel and open the workbook again.
Any code I put in after SaveAs will be executed.
As you can see from the code, I have disabled events to avoid that excel will fire a new save event on the SaveAs and course a endless loop.
I have tried many things, but nothing works.
Any help will be much appreciated.