Microsoft Excel relies on the Visual Basic language for some of its advanced features, including the use of macros. When a Visual Basic macro generates an error in Excel, it presents the user with an option to "Debug" the underlying code. If selected, this option opens the macro code in a Visual Basic editing window. You may find this undesirable, especially in situations where the current user is not the macro's creator. Disabling the Debug option and thus protecting the underlying code is possible.
Click "Tools," "Macro" and then "Visual Basic Editor."
In the Visual Basic editor window, click "Tools," then "VBAProject Properties."
Click the "Protection" tab.
Click to place a check next to "Lock project for viewing." Enter a password in the "Password" field, then type the password again in the "Confirm Password" field.
Save the workbook, then close and reopen it for the changes to take effect.
While this method protects the code in the case of an unexpected error, it is considered good programming practice to write code specifically to handle errors.