B
Barbara Ryan
Help!....I am at my wit's end. I have an Excel 2002 workbook, appr 1 MG,
containing 28 worksheets, 6 userforms, and a fair amount of VBA code.
When closing/saving the workbook, I am (randomly) experiencing the
"Microsoft Excel has encountered a problem and needs to close. We are sorry
for the inconvenience.." It seems to happen more frequently if I have
entered a row or two to several of the worksheets and then close (vs. adding
a row to 1 worksheet, then saving or closing).
Here is the code. Note: when run in debug mode, processing seems to
"hang" on the Me.Save line.
Thanks,
Barb Ryan
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo err_Workbook_BeforeClose
Let varAnswer = Null
Application.EnableEvents = False
If Not Me.Saved Then
Dim strMsg As String
strMsg = "Do you want to save the changes you made to "
strMsg = strMsg & Me.Name & "?"
varAnswer = MsgBox(strMsg, vbQuestion + vbYesNoCancel)
Select Case varAnswer
Case vbYes
Me.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
Let varAnswer = Null
Exit Sub
End Select
End If
Application.CommandBars("AUR_Custom").Delete
Let varAnswer = Null
Application.EnableEvents = True
Application.ScreenUpdating = True
exit_Workbook_BeforeClose:
Exit Sub
err_Workbook_BeforeClose:
MsgBox Err.Number & ": " & Err.Description
Resume exit_Workbook_BeforeClose
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim strBookmark As String
strBookmark = ActiveSheet.Name
If IsNull(varAnswer) Or IsEmpty(varAnswer) Then 'no need to redefine
if we are closing workbook
Application.ScreenUpdating = False
RedefineRangeNames
Application.ScreenUpdating = True
End If
Sheets(strBookmark).Select
Range("LastSaveDate").Value = Now()
End Sub
containing 28 worksheets, 6 userforms, and a fair amount of VBA code.
When closing/saving the workbook, I am (randomly) experiencing the
"Microsoft Excel has encountered a problem and needs to close. We are sorry
for the inconvenience.." It seems to happen more frequently if I have
entered a row or two to several of the worksheets and then close (vs. adding
a row to 1 worksheet, then saving or closing).
Here is the code. Note: when run in debug mode, processing seems to
"hang" on the Me.Save line.
Thanks,
Barb Ryan
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo err_Workbook_BeforeClose
Let varAnswer = Null
Application.EnableEvents = False
If Not Me.Saved Then
Dim strMsg As String
strMsg = "Do you want to save the changes you made to "
strMsg = strMsg & Me.Name & "?"
varAnswer = MsgBox(strMsg, vbQuestion + vbYesNoCancel)
Select Case varAnswer
Case vbYes
Me.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
Let varAnswer = Null
Exit Sub
End Select
End If
Application.CommandBars("AUR_Custom").Delete
Let varAnswer = Null
Application.EnableEvents = True
Application.ScreenUpdating = True
exit_Workbook_BeforeClose:
Exit Sub
err_Workbook_BeforeClose:
MsgBox Err.Number & ": " & Err.Description
Resume exit_Workbook_BeforeClose
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim strBookmark As String
strBookmark = ActiveSheet.Name
If IsNull(varAnswer) Or IsEmpty(varAnswer) Then 'no need to redefine
if we are closing workbook
Application.ScreenUpdating = False
RedefineRangeNames
Application.ScreenUpdating = True
End If
Sheets(strBookmark).Select
Range("LastSaveDate").Value = Now()
End Sub