VBA Project Password

Publication Date :

Blog Author :

Download FREE VBA Project Password Excel Template and Follow Along!
VBA Project Password Excel Template

Table Of Contents

arrow

Excel VBA Project Password

If a developer wants to hide the project's code from the other users, VBA has provided us with a tool. Using this tool, we can password protect single or multiple projects. When we right-click on a “Project,” we get an option for “VBAProject Properties.” So, for example, we can password protect the project in the protection segment.

When exposing the high-level code to the user or reader, all they have to do is to copy the code and start using it. So, it is better to protect your code with a password.

VBA Project Password
You are free to use this image on your website, templates, etc.. Please provide us with an attribution link.

How to Password Protect the VBA Project?

Like how we password protect a worksheet and workbook similarly, we can password protect the VBA codes we have written.

Follow the below steps to password protect your project.

Step 1: Create a simple Macro that needs to be protected.

Code:

Sub VBA_Project_Password()

Range("A1").Value = "This is a VBA Projet Password Enabler"

End Sub
VBA Project Password Example 1

This code will insert the "This is a VBA Project Password Enabler" to cell A1. For example, assume we need to password protect this code.

Step 2: In the "Visual Basic Editor" window, click on the "Tools" tab and choose "VBAProject Properties."

VBA Project Password Example 1-1

Step 3: This will open up the “VBAProject – Project Properties” window, which looks like the below one.

VBA Project Password Example 1-2

Step 4: In this window, we can give a name to the project.

  • We can write a description of the project.
  • We can put any other arguments as well.

At the top of this window, we can see two tabs named "General" & "Protection." Choose "Protection."

VBA Project Password Example 1-3

Step 5: In this "Protection," we need to enter the password we will use to protect the project. But, first, check the box "Lock project for viewing."

VBA Project Password Example 1-4

Step 6: Under the "Password to view project properties" section, enter the password and confirm the password once again, then click on "OK" to close the above window.

VBA Project Password Example 1-5

Now, our project is password-protected. So, we need to use the password and see to view the project's properties like a module, UserForms, and codes written inside the project.

Save the workbook, close it, and reopen it.

Go to Visual Basic Editor, and we can see the below window.

VBA Project Password Example 1-6

Since this project is locked, we could see nothing. Click on the PLUS icon on the left-hand side.

Plus sign Example 1-7

It will ask you to enter the password to see the project's properties.

VBA Project Password Example 1-8

We need to enter the password we used while protecting the project.

VBA Project Password Example 1-9

Once entering the password, click on "OK." Now, we can see the properties like worksheet names, modules, and codes.

View code Example 1-10

If we enter the wrong password, we will get the "Invalid password" message.

Invalid Example 1-11

Give Password Input Box to Run the Code

If protecting the VBA project is one thing, then asking the user to enter the password to run the password is a different thing.

The below code will ask the user to enter the password to execute the code.

Code:

Sub VBA_Project_Password()

Dim MyPassword As Variant
Dim Password As String
Password = 123

MyPassword = Application.InputBox("Enter Your Password", "Password Required to Run the Macro")

If MyPassword = Password Then
Range("A1").Value = "This is a VBA Project Password Enabler"
Else
MsgBox "Incorrect Password"
End If

End Sub

It will ask the user to enter the password when executed.

required to run Example 1-12

If the password matches, it will execute the task. Else, we will get the message below and exit the Macro.

Incorrect Example 1-13

Things to Remember

  • It is hard to recover the document in excel without a project password, so you must be sure of your password.
  • We can use third-party add-ins to break the password.