Show Message Box if Error

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

I have a macro that pulls back info from a web site. I just refresh
the code to periodically update, sometimes this web site is down and
my code returns an error. How would I include a message box if such an
instance occurs with a simple message "web site down, info not
updated"?

Thanks
 
Sub errorr()
myError = True
If myError Then
MsgBox ("something bad happened")
End If
End Sub
 
Thanks Gary, but how does it know there is an error? After each
'action' of my code, how do I say "if error, then run my sub error"
and cancel the balance of the code?
 
Hi,

You can do this:

'Place this above the line you get the error
On Error Goto ErrorHandler


Somewhere within the same sub place this

ErrorHandler:
If Err.Number = 10(you need to make this the error number you get)
msgbox "Error"
end if
 
Thanks for that, so I can 'sprinkle' my code with - On Error Goto
ErrorHandler i.e. at all major actions?

The error number, is this the type "Run Time error 1004" etc?

Thanks again
 
Yes, you can.

The ErrorHandler: is a goto line, this can be changed and you can create
others ie

On Error Goto ErrorHandler1

ErrorHandler1:
If Err.ect


On Error Goto ErrorHandler2

ErrorHandler2:
If Err.ect

Crowbar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top