VBA Project Password

Excel VBA Project Password

If a developer wants to hide the code of the project from the other users, VBA has provided us with a tool to do so, now using this tool we can password protect a single project or multiple projects when we right-click on a project we get an option for VBA project properties and in the protection segment we can password protect the project.

When the high-level code is exposed 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 linkHow to Provide Attribution?Article Link to be Hyperlinked
For eg:
Source: VBA Project Password (wallstreetmojo.com)

How to Password Protect the VBA Project?

You can download this VBA Project Password Template here – VBA Project Password Template

Like how we password protect our worksheet, workbook similarly, we can password protect the VBA codes that 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, “This is a VBA Project Password Enabler” word to the cell A1. Assume we need to password protect this code.

Step 2: In the visual basic editor window, click on the “Tools” tab, and chooses “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, and we can put any other arguments as well.

At the top of this window, we can see two tabs naming “General” & “Protection.” Choose “Protection.”

VBA Project Password Example 1-3

Step 5: In this “Protection,” we need to enter the password that we are going to use to protect the project. First, check the box “Lock project for viewing.”

VBA Project Password Example 1-4

Step 6: Now, under “Password to view project properties” section, enter the password and confirm the password once again, then click on “Ok” to close out the above window.

VBA Project Password Example 1-5

Now our project is password-protected, so in order to view the properties of the project like a module, user forms, and codes written inside the project, we need to use the password and see.

Save the workbook, close it, and reopen.

Go to Visual Basic EditorVisual Basic EditorThe Visual Basic for Applications Editor is a scripting interface. These scripts are primarily responsible for the creation and execution of macros in Microsoft software.read more, 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

Now this will ask you to enter the password to see the properties of the project.

VBA Project Password Example 1-8

Now we need to enter the password that we have used while protecting the project.

VBA Project Password Example 1-9

Once the password is entered, click on “Ok” now, we can see the properties like worksheet names, modules, and codes.

View code Example 1-10

If the wrong password is entered, then we will get the “Invalid Password” message box.

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

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

required to run Example 1-12

If the password matches, the task will be executed, or else we will get the message as below and exit the macro.

Incorrect Example 1-13

Things to Remember

This has been a guide to Excel VBA Project Password. Here we discuss how to protect our VBA code from others with a password along with practical examples and a downloadable excel template. Below you can find some useful excel VBA articles –

  • 35+ Courses
  • 120+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>