Protecting Your Excel VBA Macro Code

Applying a password to VBA

The more you use macros the more important they become and the more you want to make sure the VBA* code doesn’t get changed by someone who shouldn’t change it. You may also want to stop people viewing your code.
Unfortunately the password security that I will describe below is not bullet-proof. It can be hacked. But it will stop most people from accessing or seeing your code.
In the VBA window (Alt + F11 to open).
1. In the Project Explorer on the left of screen Right Click the file you want to protect.

Protect VBA
2. Click the VBAProject Properties option.
3. Click the Protection tab.
Protect VBA
4. Make sure the Lock project for viewing option is ticked
5. Enter a Password and then enter the Confirm password (make sure you record the password somewhere!)
6. Click OK button to apply.

You need to save and close the file and then re-open it for the changes to take effect. Once the password has been entered you can view the code as per normal.
This will mean users will have to enter the password to see the code, even if they click Debug in a macro error dialog.
*VBA = Visual Basic for Applications – a macro programming language that is a subset of Visual Basic.

Click here to see how you can run a Macro off a Quick Access Toolbar icon.

Please note: I reserve the right to delete comments that are offensive or off-topic.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.