Once my Excel Macros and VBA students start writing code, the next thing they want to do is protect it from prying eyes and fingers.
There are good reasons to protect your code: to protect your intellectual property or prevent novices from changing (and destroying) it. There is a downside to protecting your code, however. Since users won’t have access to it, they won’t be able to troubleshoot errors.
There are at least two ways to protect your VBA code: you could create an add-in, or you could use the method I am about to share below.
Creating an add-in allows an extra tight layer of security, but it might be beyond the capabilities of most people who are just getting started with Excel macros and VBA.
This method is quicker, simpler, and will prevent the majority of attempts to view your code.
Go to the Visual Basic Editor (VBE). You can get there by clicking the Macro group on the Tools tab and selecting Visual Basic Editor. The shortcut: hold down the ALT and F11 keys.
Make sure the Properties Explorer window is on the left-hand side of your screen. If it isn’t, make it visible by using the keyboard shortcut CTRL R.
If you have more than one workbook open, you will see several projects in the Properties Explorer Window. Make sure the workbook (project) you want to protect is selected by clicking the name of the project.
Go to the Tools menu and select VBA Project Properties.
Click the Protection tab. Check the Lock project from viewing box. Enter your password twice, and click OK.
Save and close your workbook. The next time you open it, your code will be protected from prying eyes (and fingers).
Grab your Excel Tips eBook by clicking here.
About the Author – Jackie Kiadii
Want to learn Excel Macros and VBA? We teach hands-on coding in a small class environment. In 2 days, you will have ample opportunity to practice what you learn and "break your code" in front of an expert who can help trouble-shoot. We also teach courses in Advanced Excel (VLOOKUP, Pivot Tables, Scenarios) and BI (Power Pivot).
Need onsite group training? Call 770.498.7333 or email us. Our courses can be customized to your needs. Jackie has provided software training for employees of The Coca-Cola Company, Emory University, Novelis, and more. This training is available for groups of 4 or more students.