Return to VBA Code Examples

VBA Project Password / Protect VBA code

Protect VBA Code

When you write code in VBA to customise your Microsoft Office application, you might end up distributing that code to clients or colleagues. If you do this, you may want to protect your code so that it can not be copied by other users.  You can protect your code by adding a password to the entire VBA Project.   This will ensure that no one can view the modules and forms in your VBA Project.

Add Password to VBA Project

  1. Select the Project you wish to protect in the Project Explorer.

VBA 17 PIC 01

2. Right-click on the Project Name, and then click on Properties in the shortcut menu.

VBA 17 PIC 02

OR

  1. Click on the Tools menu, and click on the Properties

VBA 17 PIC 03

  1. Click on the Protection tab

VBA 17 PIC 04

 

  1. Check the “Lock project for viewing” tick box, and then type in the password you wish to use to lock the project.

VBA 17 PIC 05

6. Re-type the password in the Confirm Password box, and click OK.

7. Save your file.

8. Close your File, and then re-Open it again.

9. Press F11 to go to the VBE.

10. You will notice that you cannot see any of the forms or modules

VBA 17 PIC 06

11. Click on the plus-sign to the left of your project name.

VBA 17 PIC 07

12. Type in your password to enable you to view your modules and forms.

VBA 17 PIC 08

Remove Password Protection from VBA Project

  1. Right-click on your VBA Project and select the project Properties, or go to the Tools menu and select the Properties option.
  2. Select the Protection tab, and un-check the “Lock project for viewing” check box.
  3. Click OK.

VBA 17 PIC 09

4. Remove your password from the Password and Confirm password

TIP: if you do not remove the password, the Project will be unlocked and the modules and code will be able to be viewed, but you will still need the password to go into the project properties.

  1. Save your file.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!