Project Password in Microsoft Excel VBA

Bilal Shahid Oct 20, 2022
  1. Put Password on Your VBA Project
  2. Remove Password From Your VBA Project
  3. Conclusion
Project Password in Microsoft Excel VBA

This article will discuss putting and removing project passwords in Microsoft Excel VBA.

Put Password on Your VBA Project

The VBA project usually contains essential code which can be used to alter, add, or remove important data in your Excel workbook. Therefore, Macros can be very dangerous despite being useful.

If they are run unauthorized, it may bring harm to your business logic or contribute changes that might be difficult to undo. It may also risk deleting your files or corrupting your Microsoft Office applications.

Therefore, it is important to password-protect your VBA project code since it performs Excel actions automatically, and leaving it out in the open may pose threats to the security of the data.

Note that since VBA code and Macros are high-risk in terms of security, the default setting in Microsoft Excel VBA is to disable all Macros when you password-protect them. To enable Macros, you will have to go to the "Trust Center Settings" and enable Macros by checking the option that says "Enable all macros (not recommended, potentially dangerous code can run)".

One easy way to put a password on your VBA code is through the properties options provided in the Tools menu of the Microsoft VBA environment. Let us go through the procedure to do this step by step.

  • Use a sample module in VBA which has the following code.
    Sub example()
    Range("A1") = "This is an example"
    End Sub

    Note that a module can be created in VBA by clicking on the Insert option in the menu at the top.

  • Run the VBA code. You will notice that it executes without errors, and the output is displayed in the Excel sheet as required.

    Sample VBA module output

    Note that in actual scenarios, the code written here is complicated and represents confidential business logic, and thus needs to be password protected.

  • Now, go to the "Tools" option in the menu bar. After clicking on it, choose the "VBA Project Properties" option.

    Choose VBAproject properties in the tools option

    The following window will be opened.

    VBA Project Properties

  • Now, switch the window to the "Protection" tab. This will show the following window.

    Protection Tab

  • In the Protection tab, check the option to "Lock project from viewing". Enter the password you want to create and re-enter it to confirm in the text boxes displayed; make sure you have entered the same password in both text fields, then Click on "OK" when done.

    Protection Tab set password

    Keep a strong password that is a mix of alphabets, numbers, and special characters, and make sure you remember it, or you cannot access your Macros in the VBA Project later.

Your password has been set! To check this, save your VBA Project and close both Excel and VBA files.

When you reopen the VBA Project, all modules will be hidden instead of displayed by default.

Hidden Modules

Note that if the Excel file is not saved in the Macro-enabled format, all the written code will be lost. Therefore, make sure you have saved it properly with the code.

Clicking on the "+" sign beside Modules will open a password window.

Enter password

We can test our password settings by trying to enter an incorrect password. Entering a wrong password will display the following error message box as expected.

Password Incorrect

Now, enter your correct password this time and click on "OK". You will be able to access your Macros.

This means that your VBA Project is now password protected and secure from malicious attacks.

Remove Password From Your VBA Project

Let’s move on to understanding how to remove the password on your VBA project. This process, again, is very simple and will require following a sequence of steps.

  • Open your VBA project from the Excel file. As the VBA project is password-protected, it will prompt you to enter the password when you try to access the modules.

    Enter password

    Enter your password here and click on "OK".

  • You are now authorized to access the VBA project settings. This will give you access to the VBA Project Properties section of the "Tools" menu.

    However, one point to be noted here is that you will sometimes be prompted to enter your password again once you click on the `“VBA Project Properties” option. Enter the password again if prompted.

    This will open the following window.

    VBA Project Properties

  • Switch the window to the "Protection" tab. This will show the following window.

    Uncheck Lock project from viewing in the protection tab

    Notice that the option to "Lock project from viewing" has been checked, and we can also see the hidden passwords.

  • Now, you need to uncheck the "Lock project from viewing" option. Since you already have provided the password, the VBA project will give you the authority to do so.

Now your password has been removed! You can test it by saving and reopening the VBA project and Excel file in a Macro-enabled format.


Microsoft Office applications, such as Excel, allow us to automate tasks using VBA codes known as Macros. As much as these Macros are useful in saving time, they can potentially risk the security of important data saved in Microsoft Office files.

Therefore, keeping your VBA Project password protected is good practice to disable unauthorized access and make them secure.

In this article, we explained the importance of putting a password on your VBA Project and the procedure to do so. We have also discussed the procedure to remove the password from your VBA project.

Author: Bilal Shahid
Bilal Shahid avatar Bilal Shahid avatar

Hello, I am Bilal, a research enthusiast who tends to break and make code from scratch. I dwell deep into the latest issues faced by the developer community and provide answers and different solutions. Apart from that, I am just another normal developer with a laptop, a mug of coffee, some biscuits and a thick spectacle!


Related Article - VBA Password