Macro Debug

L

LB79

Hi all!

Im trying to find a way to stop the debug option/screen when a macr
goes wrong. Ideally if a macro fails i would prefer that it sto
running and give a MSGBOX to say there is a problem. I dont want th
users to be able to get into the VB code.

Any ideas?

Thank
 
D

DNF Karran

use the "On Error Goto" statement eg.

sub mySub

On error goto errHandle


Code
-------------------


Exit Sub

errHandle:

msgbox "An error has occurred"

End sub

Dunca
 
F

Frank abel

Hi
best way would be to PREVENT all such kind of errors in
your code. You could use statements like

on error resume next

or something like
on error goto errhandler

Have a look at the VBA help for more on this topic
 
A

Amedee Van Gasse

LB79 said:
Hi all!

Im trying to find a way to stop the debug option/screen when a macro
goes wrong. Ideally if a macro fails i would prefer that it stop
running and give a MSGBOX to say there is a problem. I dont want the
users to be able to get into the VB code.

Any ideas?

Thanks

Use On Error:


On Error Resume Next
' Skips the line with the error and goes to the next line


or


Sub YourSub()

On Error Goto ErrHandler
' Your code
Exit Sub ' End the sub here if there was no error.

:ErrHandler
MsgBox "There was an error, please report this to LB79" _
& vbNewLine & "The error number was: " & Err.Number _
& vbNewLine & "The error message was:" & Err.Description
End Sub

--
Amedee Van Gasse using XanaNews 1.16.3.1
If it has an "X" in the name, it must be Linux?
Please don't thank me in advance. Thank me afterwards if it works or
hit me in the face if it doesn't. ;-)

I found 2 small shortcomings on www.excelforum.com:
1. You do *not* have to pay for access to 2. A *real* newsreader (not Outlook Express) is actually very easy to
use. See www.newsreaders.com for more info.
 
L

LB79

This is great - Just one other question on it...

can i have the first part in my normal macros and the second part in
another? For example:


Sub mymacro()
On Error Application.Run "'Workbook.xls'!Error"
End Sub

Sub Error()
MsgBox "There is an error"
End Sub
 
F

Frank Kabel

Hi
no, yiou have to use on error goto. But you may use
something like

sub foo()
on error goto errhandler

'your code
exit sub
errhandler:
raiseErrmsg(1)
end

sub raiseErrmsg(i as integer)
select case i
case 1:
msgbox "Another error"
case 2:
msgbox "different error"
end select
end sub
 
Top