In the VBA Editor, choose VBA Project Properties, then the Protection tab.
There, check "Lock project for viewing", enter a password (twice) and then
save the workbook. Note that this level of security is notoriously weak.
There are many password breakers readily available on the net. I use VBAKey
from Passware (about $40) and it can crack any VBA project password in a
matter of seconds. (As an aside, VBAKey doesn't necessarily return the
actual password used on the project. Instead, it finds a password that will
unlock the project, which is not necessarily the actual password used.)
You should think of VBA protection as a mechanism to prevent the honest user
from making honest mistakes. It should not be used to protect proprietary
data or code with intellectual property value. If you really need to lock
down the code, you should write a COM Add-In or an Automation Add-In in VB6
or NET. See
http://www.cpearson.com/Excel/CreatingCOMAddIn.aspx and
http://www.cpearson.com/Excel/AutomationAddIns.aspx and
http://www.cpearson.com/Excel/CreatingNETFunctionLib.aspx for example code.
With these types of add-ins, no source code is ever distributed to the
user -- only compiled machine code or MSIL is distributed to the end user--
so you don't have to worry about users viewing and/or modifying code.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)