top of page

You are learning Macros in MS Excel

How to password-protect a macro from editing?

Excel offers a way to password-protect your macros from viewing and editing. Here's how to do it:

1. Open the Visual Basic Editor:
- Press `Alt + F11` on your keyboard. This will open the VBA editor where your macros reside.

2. Access VBA Project Properties:
- Right-click on your project name (usually "VBAProject (filename.xlsm)") in the Project Explorer window (left side pane).
- Select "VBAProject Properties..." from the context menu.

3. Enable Password Protection:
- In the VBAProject Properties window, navigate to the "Protection" tab.
- Check the box next to "Lock project for viewing" and enter your desired password in the "Password" and "Confirm password" fields.

4. Save and Close:
- Click "OK" to save the changes.
- Close the VBA editor (or press `Alt + F11` again).

Important Notes:

- This method prevents users from viewing or editing your macro code. They will be prompted to enter a password when trying to open the VBA project.
- It's crucial to remember your password. If you lose it, there's no way to recover the password or access the code without breaking the protection (which can be complex and unreliable).
- Password protection in VBA offers a basic level of security. It's not foolproof and determined users with advanced knowledge might still be able to access the code through external methods.

bottom of page