Jeff,
A simpler code version might be the answer.
Give this a try...
'-------------------------------------------------
Sub RemoveSubtotals()
On Error GoTo handleCancel
Application.EnableCancelKey = xlErrorHandler
If ActiveSheet.ProtectContents Then
MsgBox "Please unprotect the sheet. ", vbInformation, _
" Remove Subtotals Program"
Exit Sub
End If
Application.StatusBar = "REMOVING SUBTOTALS..."
Application.ScreenUpdating = False
Selection.RemoveSubtotal
Application.StatusBar = False
Application.ScreenUpdating = True
Exit Sub
handleCancel:
Application.ScreenUpdating = True
Application.StatusBar = False
If Err.Number = 18 Then
MsgBox "User interrupt occurred. Program will close. ", _
vbExclamation, " Remove Subtotals Program"
Else
MsgBox "Error Number: " & Err.Number & vbCrLf & Err.Description, _
vbCritical, " Remove Subtotals Program"
End If
End Sub
'-----------------------------------------------------------
Regards,
Jim Cone
San Francisco, USA
"Jeff" <jeffreywsmith@earthlink.net> wrote in message
news:1109613905.019388.231880@z14g2000cwz.googlegroups.com...
> Hi all,
>
> I have an xla application that includes a number of macros that I am
> trying to Error-proof. I am particularly interested in doing so
> because some other things I have going on in this app led me to employ
> some of Dave Peterson's LockWindowUpdate code (details in the code
> below). The first of the 3 macros below is an example of the macros I
> am trying to error-proof (& the only error I am really concerned with
> trapping is Error 18 which is supposed to be generated if the user
> cancels), the other two are supporting macros that might be invoked.
>
> I presently have coded for both Error 18 and Error 1004 (which is what
> actually gets generated when I [ESC] from this procedure when Removing
> Subtotals from a fairly large array of data). So the first of my two
> questions are:
>
> 1) Can anyone can shed any light on why Error 18 isn't generated when
> the user presses [ESC]?
>
> and, more importantly,
>
> 2) When I execute this Remove Subtotals macro by stepping through it
> (with the help of a Breakpoint), the MsgBox DOES display, allowing the
> user to respond; but when I just run it from a toolbar button and press
> [ESC] while the Selection.RemoveSubtotal is executing (again, on a
> large enough array of data to let you press [ESC]), the macro just ends
> WITHOUT displaying any MsgBox. Can anyone help me understand why this
> works when stepping through it but not when executed normally?
>
> Thanks!
>
> Jeff
>
> code follows:
- snip -
Bookmarks