Protecting your VBA code

People don't usually try to change your VBA code. But if they do try, and they don't know what they're doing, it can be a real mess. Here I show how to combat that by password protecting your VBA code. (To see how to protect your workbooks and worksheets themselves, click here.)

 

Protecting your VBA code

1. Go to the visual basic editor, either through the developer tab, or by hitting Alt-F11.

Go to VB editor

 

2. In the Tools Menu, select "VBAProject Properties..."

Project Properties

 

3. Go to the Protection tab, check the "Lock project for viewing" box, and type in and confirm your password. Hit OK.

Password

 

Editing your protected code

After saving and closing the workbook, re-open it. Now when you try to open your VBA code, you will first have to enter your password. (So be sure not to lose/forget your password!)

Enter Password

 

If you no longer want your code to be password protected, go back into the VBAProject Properties (shown above) and uncheck the "Lock project for viewing" box.

 

 

Back to Resources page.