Prevent VBE from opening on errors?

E

Ed from AZ

In XL 2003, when my code errors (more than I want it to!!), the VBE
opens with the offending line of code highlighted in yellow. How can
I prevent this from happening so the user doesn't see the code?

Ed
 
S

semiopen

In XL 2003, when my code errors (more than I want it to!!), the VBE
opens with the offending line of code highlighted in yellow.  How can
I prevent this from happening so the user doesn't see the code?

Ed

You need to look into error handling. Briefly, suppose that MySub() is
crashing at times. Modify MySub() as follows

Sub MySub()

On Error GoTo ErrHandler 'other labels for the error handler are ok

'The original code goes here

Exit Sub 'put this line where you had End Sub in the original code

ErrHandler:
'put code to handle the error here, for example:

MsgBox "An error has been encountered"

End Sub

It is a relatively involved topic. You could start by looking up "On
Error" in the on line help.

hth
 
J

Jim Rech

Your first line of defense is addressing your bugs, and it will have other
benefits like your code will run to completion successfully.<g>

But in the meantime, if you don't want users to see your code when it
errors (or any other time), protect the project via Tools, VB Project
Properties, Protection.
 
E

Ed from AZ

Thanks, Jim. Until I can kill all my bugs, I'll use the protection.
I've got the sheet protected, and I'm not used to using it like that
so I've missed a spot or two where I need to unprotect. But if the
VBE opens up, there's the Unprotect with the password in plain sight.

Ed
 
D

Dave Peterson

If you protect the project (not the worksheet, workbook or file), then when the
code blows up, the user won't see the code.

But be aware that protection of the project isn't foolproof. It can be broken
by some free tools on the internet, along with password cracking programs (that
are not free).
 

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

Top