I have an odd one here. It took me a while to track down where the problem is but now it seems to be isolated to asking the user if they're sure before calling ActiveWorkbook.Close.
The macros below runs when you click an icon on the worksheet.
The code executes just fine - the message box comes up, if you cancel it there's no problems, and if you don't cancel it the file closes. But then when you reopen the file it comes up with the error message "Microsoft Excel has stopped working, etc" and then goes through a restart.
The error seems to be because of the "idiot test". If you comment it out there's no problem. Same if you close with Ctrl-W. I can live without the test but it would be good to know why it's creating the error.
I'm running Excel 2010 by the way.
The macros below runs when you click an icon on the worksheet.
Code:
Sub CloseFile()
Dim answer As Variant
Application.ScreenUpdating = False
answer = MsgBox("Are you sure you want to exit?", vbYesNo, "Title") 'idiot test
If answer = vbYes Then
ActiveWorkbook.Close
End If
Application.ScreenUpdating = True
End Sub
The code executes just fine - the message box comes up, if you cancel it there's no problems, and if you don't cancel it the file closes. But then when you reopen the file it comes up with the error message "Microsoft Excel has stopped working, etc" and then goes through a restart.
The error seems to be because of the "idiot test". If you comment it out there's no problem. Same if you close with Ctrl-W. I can live without the test but it would be good to know why it's creating the error.
I'm running Excel 2010 by the way.