VBA & Macro Problems

How to Prevent an Excel Workbook from Opening When Macros Are Disabled

Huda QurayshiHuda Qurayshi Nov 13, 2026 869 views

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.

How to Prevent an Excel Workbook from Opening When Macros Are Disabled
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Visual Basic Editor

In Excel, press Alt+F11 to open the Visual Basic Editor.

2
Open VBAProject Properties

Click Tools > VBAProject Properties in the Visual Basic Editor menu.

3
Enable lock and set a password

Select the Protection tab, check Lock project for viewing, enter and confirm a password, and then click OK.

4
Save the macro-enabled workbook

Save the file as an Excel Macro-Enabled Workbook (.xlsm) to keep the protected VBA project.

Protect the VBA Project with a Password to Restrict Access
Password recovery: If you forget the VBA project password, recovery is not supported. Store the password in a secure location.
Free Microsoft Office alternative

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. 1. Download WPS Office: Go to the official WPS Office download page and download the free version for your device.
  2. 2. Install and launch WPS Office: Install WPS Office, then open WPS Spreadsheets from the desktop or Start menu.
  3. 3. Open the macro-enabled workbook: Click Menu > Open and select the .xlsm workbook to continue working with it.
  4. 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.
Opens and saves Excel .xlsm files with macro supportFree to use with a familiar ribbon interfaceLightweight installation with fast startupCompatible with Microsoft Excel workbooks and VBA macrosSeamless migration from Microsoft Office
microsoft office alternative - wps office

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.