And don't forget to reset the error catching before getting out of the
routine.
On Error GoTo 0
Exit Sub
Error handling is a touchy subject for a lot of people.
I tend to try and handle stuff "inline" as it were, and I use a variable to
catch the error number so that I can reset the handler immediately.
Public lgErrNum as long
Sub Update()
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
Application.StatusBar = "Please wait while updating..."
Application.Wait Now + TimeValue("00:00:02")
On Error Resume next
Sheets("Web").Select
lgErrNum = Err.Number
On Error GoTo 0
Select case lgErrNum
Case 0
Case Else
Application.ScreenUpdating = True
Application.DisplayStatusBar = False
MsgBox "Please relogin the web"
Exit Sub
End Select
Range("A40").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("TOP").Select
Application.StatusBar = False
End Sub
Or....
On Error Resume next
Sheets("Web").Select
lgErrNum = Err.Number
On Error GoTo 0
Select case lgErrNum
Case 0
Range("A40").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("TOP").Select
case else
MsgBox "Please relogin the web"
End Select
Application.ScreenUpdating = True
Application.DisplayStatusBar = False
I's more coding I know but each error is dealt with there and then and it
becomes pretty standard. Also each error condition can be dealt with in the
select statement.