How to Encrypt VBA Macros in Word
🔍 WiseChecker

How to Encrypt VBA Macros in Word

You want to protect the code inside your VBA macros from unauthorized viewing or editing in Word. The Visual Basic Editor includes a built-in password protection feature that encrypts the entire macro project. This article explains how to set a password on your VBA project, what the encryption actually protects, and how to avoid common pitfalls that can lock you out of your own code.

Key Takeaways: Encrypting VBA Macros in Word

  • Developer tab > Visual Basic > Tools > VBAProject Properties > Protection tab: The only place to set a password that encrypts the entire macro project.
  • Checkbox “Lock project for viewing”: Must be enabled for the password to take effect when the document is closed and reopened.
  • Password recovery is impossible: Microsoft does not offer a password reset for VBA projects. You must store the password in a password manager or lose access permanently.

What VBA Project Encryption Does and Does Not Protect

VBA project encryption in Word uses a password to protect the macro source code stored inside a document or template. When you set a password and enable “Lock project for viewing,” anyone who opens the Visual Basic Editor will see a prompt asking for the password before the code modules, user forms, and class modules are displayed. Without the correct password, the project tree is visible but all code is hidden and cannot be exported.

The encryption is applied at the VBA project level, not at the document level. This means the document itself remains fully functional and editable. Macros continue to run normally even when the project is locked. The password only restricts access to the code inside the editor.

Important limitations exist. The encryption is not military-grade. Third-party tools exist that can recover or remove VBA passwords, though this violates Microsoft’s terms of service. The password is stored inside the document binary, not in a remote server. If you lose the password, there is no recovery mechanism provided by Microsoft.

Steps to Encrypt VBA Macros in Word

Follow these steps to add password protection to your VBA macro project. You must have access to the Developer tab in Word. If the Developer tab is not visible, right-click the ribbon and choose Customize the Ribbon, then check Developer in the right column and click OK.

  1. Open the Visual Basic Editor
    On the Developer tab, click Visual Basic. Alternatively, press Alt+F11 on your keyboard. The editor opens in a separate window.
  2. Select the VBA project
    In the Project Explorer pane on the left, click the project that corresponds to your document. The project name typically matches the document filename, such as “Normal” for the global template or “Document1” for an open document.
  3. Open the project properties
    On the menu bar at the top of the editor, click Tools, then click VBAProject Properties. The Properties dialog opens.
  4. Go to the Protection tab
    In the Properties dialog, click the Protection tab. This tab contains the password fields and the lock checkbox.
  5. Set the password
    In the Password text box, type a strong password. Retype the same password in the Confirm password text box. Use a mix of uppercase letters, lowercase letters, digits, and symbols. Do not use personal information.
  6. Enable project locking
    Check the box labeled “Lock project for viewing.” This checkbox must be selected for the password to take effect. If you leave it unchecked, the password is stored but not enforced.
  7. Save and close
    Click OK to close the Properties dialog. Save the document by pressing Ctrl+S or clicking the Save icon in the Quick Access Toolbar. Close the Visual Basic Editor. The document now has an encrypted macro project.

Common Issues When Encrypting VBA Macros

Word Prompts for Password Every Time the Document Opens

This occurs when you set a password but also have the document set to open macros automatically. The VBA project password prompt appears once per session when the editor is opened, not when the document is opened. If you see the prompt every time you open the document, you may have enabled the password prompt in the Trust Center under Macro Settings. To change this, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select “Disable all macros with notification.” This setting shows a security warning bar instead of a password prompt.

The Password Dialog Does Not Appear

The password dialog only appears when someone opens the Visual Basic Editor. If you double-click a module in the Project Explorer, Word checks the password before displaying the code. If the dialog does not appear, verify that the checkbox “Lock project for viewing” is checked in the Protection tab. If the checkbox is not selected, the password is stored but not enforced. Open the Properties dialog again, check the box, and save the document.

Password Lost or Forgotten

There is no official way to recover a lost VBA project password. Microsoft does not provide a password reset tool or backdoor. If you lose the password, the macro code is permanently inaccessible. The only recovery methods involve third-party password recovery software, which may violate the software license agreement and may not work on newer file formats. Always store your VBA project password in a password manager before applying it.

VBA Project Password Protection vs Document Encryption

Item VBA Project Password Document Encryption (Word Password)
What it protects Macro source code and VBA modules Entire document content including text, images, and formatting
How it is applied Tools > VBAProject Properties > Protection tab File > Info > Protect Document > Encrypt with Password
Macro execution Macros continue to run normally Macros cannot be opened until the document password is entered
Password recovery Not supported by Microsoft Not supported by Microsoft
Encryption algorithm Weak obfuscation, removable by third-party tools AES-256 in Office 2016 and later

VBA project encryption is a basic protection layer meant to prevent casual viewing of your macro code. For strong document security, use Word’s built-in document encryption with a strong password. Combine both methods when you need to protect both the document content and the macro source code. Always keep a backup copy of your document without the VBA password in a secure location.