How to Fix Excel Macro Recording Not Saving a Workbook Password
Question details
The user is attempting to use the Excel Macro Recorder to automate the process of password-protecting a workbook, but the resulting macro fails to save or prompt for the password when run.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Recording an Excel macro to automate adding a password to secure a workbook.
- Observed behavior
- When the recorded macro is executed again, it runs but completely bypasses the password protection step, leaving the workbook unprotected.
Before modifying your macros, ensure that the Developer tab is enabled in your ribbon and that you have saved a backup copy of your workbook to prevent accidental data loss.
Use VBA Code to Explicitly Set the Workbook Password
Bypass the Macro Recorder limitations by manually writing a VBA script using the Workbook.Password property to apply the protection.
The built-in Record Macro feature is excellent for sequential cell actions, but it cannot reliably capture system prompts like password dialog boxes. By writing a few lines of VBA code, you directly command the application to assign a password to the workbook file.
If you are using a Mac, remember that the file system structure is different from Windows. Any explicit file paths in your VBA code must use Mac-compatible syntax (e.g., using forward slashes) for the save function to work properly.
Navigate to the Developer tab on your ribbon and click on 'Visual Basic', or press Alt + F11 on your keyboard.
In the Visual Basic for Applications window, right-click on your workbook in the Project Explorer on the left, select 'Insert', and click on 'Module'.
Type the following code into the module window: Sub ProtectWorkbook() ActiveWorkbook.Password = "YourSecretPassword" ActiveWorkbook.Save End Sub
Close the VBA Editor to return to your workbook. Click on 'Macros' in the Developer tab, select 'ProtectWorkbook', and click 'Run'.

Easily Manage Macros and Protect Workbooks with WPS Office
WPS Spreadsheet offers powerful VBA support and intuitive built-in file encryption. You can write and run your macros seamlessly while enjoying full compatibility with Microsoft Excel files, or use the native UI to encrypt files without writing any code.
- 1. Open WPS Spreadsheet: Launch WPS Office and open your existing macro-enabled spreadsheet or create a new one.
- 2. Access the Developer Tools: Click on the 'Tools' or 'Developer' tab in the top ribbon to easily access the VBA Editor and Macro features.
- 3. Write Your Macro or Encrypt Manually: Use the VBA Editor to assign a password programmatically, or simply go to Menu > Document Encryption to secure your file instantly without coding.

Frequently Asked Questions
Why does the Excel Macro Recorder ignore my password inputs?
The Macro Recorder is designed to capture standard spreadsheet interactions like formatting and data entry. It actively ignores security-related dialog boxes, such as password prompts, to prevent sensitive passwords from being inadvertently stored as plain text in the recorded macro code.
How do I remove the password using VBA?
You can remove the password by running a similar VBA macro where you set the password to an empty string. Open your VBA module, write the code `ActiveWorkbook.Password = ""`, and then execute the script to remove protection.
Are VBA macros compatible between Windows and Mac?
Basic VBA commands are highly compatible, but file paths are not. Mac uses forward slashes or colons depending on the OS version, while Windows uses backslashes. You must update any hardcoded save paths in your VBA script to Mac-compatible syntax if you switch platforms.
Does setting a workbook password via macro fully encrypt the file?
Using the `ActiveWorkbook.Password` property in VBA does encrypt the file requiring a password to open it. However, if maximum protection is required for sensitive data, you should use the application's built-in Save As > Tools > General Options encryption method to apply stronger security algorithms.




