VBA & Macro Problems

Fix Excel VBA Project Protection in an XLSX Workbook

Steve KSteve K Nov 22, 2026 868 views

Question details

The user needs to protect an Excel VBA project and retain it in the workbook.

Fix Excel VBA Project Protection in an XLSX Workbook
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user wants to lock a workbook's VBA project for viewing with a password.
Observed behavior
The XLSX format cannot store VBA macros, so it cannot retain a protected VBA project.
Before you start

Open the workbook that still contains the VBA project and check its current file format. If the macros were already removed when the file was saved as XLSX, locate a copy that still contains them.

Solution 1Recommended

Save as XLSM and lock the VBA project

Use a macro-enabled format to retain the VBA project, then enable its viewing protection.

1
Save as a macro-enabled workbook

In Excel, select File > Save As, choose Excel Macro-Enabled Workbook (*.xlsm), and save the file.

2
Open the VBA editor

Select Developer > Visual Basic. If the Developer tab is hidden, enable it through Excel's ribbon customization settings.

3
Select the project

In the VBA editor's Project Explorer, select the VBA project for the XLSM workbook, then choose Tools > VBAProject Properties.

4
Set the password

Open the Protection tab, select Lock Project for Viewing, enter and confirm a password, and select OK.

5
Save and reopen

Save the workbook, close Excel, and reopen the XLSM file. In the VBA editor, try to expand the project to check that a password is requested.

Save as XLSM and lock the VBA project
Protection is not encryption: VBA project protection restricts viewing but is not a strong security boundary for sensitive code. It does not prevent macros from running.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility for an easier move between office suites. Excel's VBA project protection must still be configured in Excel; check VBA support in your WPS version before relying on macros.

Open and edit Excel spreadsheets in a familiar interfaceCompatible with Microsoft Excel formats, including XLSX and XLSMUse a free, lightweight office suite for everyday spreadsheet workMove between common Microsoft Office file formats with fewer workflow changes
microsoft office alternative - wps office

Frequently Asked Questions

Can an XLSX file keep my VBA project?

No. XLSX does not support VBA macros. Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) while you still have a copy containing the project.

Why does Excel not ask for my VBA password immediately?

After setting the password in Tools > VBAProject Properties > Protection, save the workbook, close Excel, and reopen it. Then try to expand the project in the VBA editor.

Does locking the VBA project stop macros from running?

No. Lock Project for Viewing restricts access to the project in the VBA editor; macro execution is controlled separately by Excel's macro security settings.

Can I recover macros by changing an XLSX file to XLSM?

Changing the format cannot restore macros that were already removed. Open a copy that still contains the VBA project, then save it as an XLSM file.