WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Blog
  • Free Video Tutorials
  • Courses
  • All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA Project Password

VBA Project Password

By Jeevan A YJeevan A Y | Reviewed By Dheeraj VaidyaDheeraj Vaidya, CFA, FRM

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

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.

Popular Course in this category
Sale
All in One Excel VBA Bundle (35 Courses with Projects)
4.9 (1,353 ratings)
35+ Courses | 120+ Hours | Full Lifetime Access | Certificate of Completion
View Course

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 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

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

  • Without a Project password, it is hard to recover the document in excel, so you need to absolutely sure of what your password is.
  • You can use third-party add-ins to break the password.

Recommended Articles

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 –

  • Excel Protect Formulas
  • Unprotect Excel Workbook
  • Protect Sheet in VBA
  • VBA UnProtect Sheet
  • VBA Borders
0 Shares
Share
Tweet
Share
All in One Excel VBA Bundle (35 Courses with Projects)
  • 35+ Courses
  • 120+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

WallStreetMojo

Download VBA Project Password Template

Special Offer - All in One Financial Analyst Bundle (250+ Courses, 40+ Projects) View More