How to Prevent an Excel Workbook from Opening When Macros Are Disabled
Question details
The user needs to restrict access to an Excel workbook when VBA macros are disabled and to understand the security limitations of Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user has a macro-enabled Excel workbook that should not be used or viewed normally when macros are disabled.
- Observed behavior
- The workbook should remain protected or display a warning when macros are not enabled, while accepting that Excel cannot reliably detect disabled macros from VBA code.
Make sure you can open the workbook with macros enabled and have access to the Visual Basic Editor. If the workbook is shared or protected, confirm that you have permission to change VBA project properties and Trust Center settings.
Protect the VBA Project with a Password to Restrict Access
Use this when you want to prevent users from viewing or modifying the macros that control workbook behavior.
Locking the VBA project stops casual users from inspecting or modifying macro code. It does not by itself prevent workbook data from being viewed, so combine it with worksheet and workbook protection when necessary.
In Excel, press Alt+F11 to open the Visual Basic Editor.
Click Tools > VBAProject Properties in the Visual Basic Editor menu.
Select the Protection tab, check Lock project for viewing, enter and confirm a password, and then click OK.
Save the file as an Excel Macro-Enabled Workbook (.xlsm) to keep the protected VBA project.

Add a Warning Sheet That Only Disappears When Macros Run
Use this to show a clear warning and keep the main content hidden when VBA macros are not enabled.
Digitally Sign the VBA Project and Configure Trust Center Settings
Use this to verify the source of the macros and control how Excel handles macro-enabled workbooks.
Open and Protect Macro-Enabled Workbooks in WPS Office
WPS Office opens Excel workbooks, including macro-enabled .xlsm files, in a familiar ribbon interface. It is free, lightweight, and format-compatible so you can migrate from Microsoft Office without losing access to your workbooks or macro features.
- 1. Download WPS Office: Go to the official WPS Office download page and download the free version for your device.
- 2. Install and launch WPS Office: Install WPS Office, then open WPS Spreadsheets from the desktop or Start menu.
- 3. Open the macro-enabled workbook: Click Menu > Open and select the .xlsm workbook to continue working with it.
- 4. Review macro security settings: Use the Developer tab or the macro security options in WPS Office to configure how macros are handled on your system.

Frequently Asked Questions
Can an Excel workbook detect that macros are disabled and close itself automatically?
No, because VBA code does not run when macros are disabled. A visible warning sheet is the common workaround: the startup code hides it only when macros are enabled, so it remains visible when macros are disabled.
How do I lock the VBA project in Excel so users cannot view the macro code?
Open the Visual Basic Editor with Alt+F11, go to Tools > VBAProject Properties > Protection, check Lock project for viewing, set a password, and save the workbook as a macro-enabled file.
Does protecting the VBA project prevent users from viewing worksheet data?
No, VBA project protection only restricts access to macro code. You also need to protect worksheets and the workbook structure, and consider a warning sheet that hides content when macros are not enabled.
Can a digital signature stop macros from being disabled?
No, a digital signature verifies the source of the macro but does not prevent users from disabling macros. Trust Center settings control whether macros are enabled, disabled, or run with a notification.
Will WPS Office open Excel files that contain VBA macros?
Yes, WPS Office supports opening and editing macro-enabled Excel workbooks such as .xlsm files and provides macro security options in a familiar interface.




