Fix Excel VBA Project Protection in an XLSX Workbook
Question details
The user needs to protect an Excel VBA project and retain it in the 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.
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.
Save as XLSM and lock the VBA project
Use a macro-enabled format to retain the VBA project, then enable its viewing protection.
In Excel, select File > Save As, choose Excel Macro-Enabled Workbook (*.xlsm), and save the file.
Select Developer > Visual Basic. If the Developer tab is hidden, enable it through Excel's ribbon customization settings.
In the VBA editor's Project Explorer, select the VBA project for the XLSM workbook, then choose Tools > VBAProject Properties.
Open the Protection tab, select Lock Project for Viewing, enter and confirm a password, and select OK.
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.

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.

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.




