VBA & Macro Problems

How to Protect an Excel VBA Project with a Password

Jason MillerJason Miller Oct 26, 2026 868 views

Question details

The user needs to securely password protect their Excel VBA project but finds that the protection does not prompt for a password when the file is reopened.

How to Protect an Excel VBA Project with a Password
Product
Excel
Device & OS
not provided
Scenario
Securing macro code and preventing unauthorized users from viewing or modifying VBA modules and worksheet visibility settings.
Observed behavior
The Visual Basic environment opens without requesting a password, and the code/worksheet visibility remains completely accessible despite configuring the 'Lock project for viewing' setting.
Before you start

Ensure your Excel workbook is saved in a macro-enabled format (.xlsm or .xlsb) before applying VBA project protection, and make sure you remember the password you are about to set.

Solution 1Recommended

Add Dummy Code and Apply VBA Project Protection

Excel may fail to lock a completely empty VBA project. Adding a simple module ensures the password protection activates correctly upon restart.

VBA project protection may appear ineffective if the project contains no actual code. Excel sometimes fails to save the 'Lock project for viewing' state for an empty project. By inserting a basic standard module, you can force the application to register and apply the security settings properly.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) environment in your active Excel workbook.

2
Insert a Standard Module

In the Project Explorer panel on the left, right-click on your VBAProject, select 'Insert', and click 'Module'. Enter a simple blank procedure such as 'Sub Test()' followed by 'End Sub'.

3
Open Project Properties

Click on 'Tools' in the top menu bar, then select 'VBAProject Properties...' to open the configuration dialog.

4
Configure Protection Settings

Switch to the 'Protection' tab. Check the box labeled 'Lock project for viewing'. Enter your desired password in the 'Password' field and type it again in the 'Confirm password' field.

5
Save and Restart Excel

Click 'OK' to apply the settings. Save your workbook, then completely close the Excel application. Reopen the file and press Alt + F11 to verify that a password is now required to view the code.

Add Dummy Code and Apply VBA Project Protection
Application Restart Required: The VBA project protection will not take effect immediately while the file remains open. You must close Excel completely and reopen the workbook to trigger the password prompt.
Advanced Spreadsheet Management

Protect Your Macros Securely with WPS Spreadsheet

WPS Office provides robust VBA support, allowing you to create, edit, and securely password-protect your macro projects with seamless Microsoft Excel compatibility.

  1. 1. Access the VBA Editor: Open your macro-enabled workbook in WPS Spreadsheet, navigate to the Developer tab, and click on the 'Visual Basic' icon.
  2. 2. Navigate to Protection Settings: In the VBA Editor, click on Tools in the top menu and select 'VBAProject Properties', then switch to the 'Protection' tab.
  3. 3. Set Your Password: Check the 'Lock project for viewing' option, type a secure password, confirm it, and click OK.
  4. 4. Save and Apply: Save the workbook. Close and reopen the file in WPS Spreadsheet to ensure the VBA project is successfully locked behind the password.
Fully compatible with Microsoft Excel macro formats (.xlsm, .xlsb)Comprehensive built-in VBA editor for advanced automationReliable macro security and project locking mechanismsLightweight architecture for fast script execution
microsoft office alternative - wps office

Frequently Asked Questions

Why can I still view the VBA code after setting a password?

This typically happens for two reasons: either the Excel application hasn't been completely closed and reopened since applying the password, or the VBA project is entirely empty. Ensure you add at least one module (even a blank Sub) and restart the application.

How do I unlock a password-protected VBA project to edit it?

Open the workbook, press Alt + F11 to launch the VBA editor, and double-click the locked project in the Project Explorer. Enter the password when prompted. To permanently remove the password, go to Tools > VBAProject Properties > Protection, uncheck the lock option, and clear the password fields.

Does protecting the VBA project prevent users from running the macros?

No, password-protecting the VBA project only prevents users from viewing or editing the underlying code. The macros themselves will still execute normally when triggered from buttons or shortcuts within the workbook.