NessPJ
Active Member
- Joined
- May 10, 2011
- Messages
- 414
- Office Version
- 365
Hi all,
I made an error handler, but i would like to execute a few steps after reporting the error. But the routine does not seem to be executing them.
Here's my code:
Am i doing something wrong?
I made an error handler, but i would like to execute a few steps after reporting the error. But the routine does not seem to be executing them.
Here's my code:
VBA Code:
Private Sub Test()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error GoTo Error
DivisionByZero = 1 / 0
'Error Handler
Error:
If Err.Number <> 0 Then
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & "Error Line: " & Erl & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
End If
Resume Next
PROTOFF (Password)
Sheets("Parameters").Activate
Sheets("Parameters").Range("B9").Value = "#ERR"
Sheets("Menu").Activate
PROTON (Password)
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Exit Sub
End Sub
Private Function PROTOFF(Password As String)
' Loop through all sheets in the workbook
For i = 1 To Sheets.Count
Sheets(i).Unprotect (Password)
Next i
End Function
Private Function PROTON(Password As String)
For i = 1 To Sheets.Count
Sheets(i).Protect DrawingObjects:=True, Contents:=True, AllowUsingPivotTables:=True, Scenarios:=True _
, AllowFiltering:=True, Password:=Password
Next i
End Function
Am i doing something wrong?