EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 120+ Courses All in One Bundle
  • Login
Home VBA VBA Resources VBA Tips VBA Project Password
Secondary Sidebar
How to Develop a Communication Plan?

Benefit Cost Ratio

Agile Product Management

What is Linker?

Test Management

Maven Versions

VBA Project Password

VBA Project Password

Excel VBA Project Password

Excel VBA Project Password is a kind of tool in VBA which is used to protect the project code using the password. By this, we can protect the worksheet and the projects as well. If we protect the project, in another way we are also protecting the Excel workbook as well. We can either protect or preserve one project in VBA or multiple projects. And this is can be using the same procedure for both categories.

Usually, most of the code written in VBA has or requires only a project in which all the worksheets, modules, user forms can be seen.

How to Use VBA Project Password in VBA?

To protect the VBA Project using Password or to enable the password set in a VBA Project, we will be using the VBA Project properties option which is available in the Tools menu bar in VBA as shown in the below steps. Then we will be getting the VBA Project properties window where we can set the password whichever we want, to protect the currently available projects in VBA.

All in One Financial Analyst Bundle(250+ Courses, 40+ Projects)
Financial ModelingInvestment BankingUS GAAPCFA-Level 1 & 2
Equity ResearchM & A ModelingPrivate Equity ModelingForex Trading
Price
View Courses
250+ Online Courses | 40+ Projects | 1000+ Hours | Verifiable Certificates | Lifetime Access
4.9 (86,522 ratings)
You can download this VBA Project Password Excel Template here – VBA Project Password Excel Template

Example #1

To apply a password in the VBA Project, first, we need to have a code in a module. This could be any simple code as per our choice or requirement. For this, follow the below steps:

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Step 1: Insert a new module inside Visual Basic Editor (VBE). Click on Insert tab > select Module.

Insert Module

Step 2: Now write the subprocedure for the VBA Project password.

Code:

Sub VBA_ProjectPW()

End Sub

VBA Project Password Example 1-2

Step 3: Use DIM to define a variable as an Integer.

Code:

Sub VBA_ProjectPW()

Dim A As Integer

End Sub

Integer Example 1-3

Step 4: And last to close the code, use Debug print to print the value whichever could be stored in variable A. This is the simplest code that we protect using the VBA Project password.

Code:

Sub VBA_ProjectPW()

Dim A As Integer
Debug.Print A

End Sub

VBA Project Password Example 1-4

Step 5: To test this, we would run this code by pressing F5 or Play Button is mentioned below the menu bar.

We would notice that the code has run without any error. Now to protect the VBA Project with a password, go to Tools menu option and select VBA Project properties as shown below.

VBA Project properties Example 1-5

Step 6: We will then get the Project Properties as shown below. And in that go to the Protection tab.

Protection Tab Example 1-6

Step 7: Now in the Protection tab’s Password and Confirm password section write the password which you want. Preferably the password should be strong enough not be cracked easily by anyone.

VBA Project Password Example 1-7

Step 8: We have chosen the password as “Pa$$w0rd123” in the combination of Upper case, lower case, special character, and numbers. The password should be the same in Password and Confirm Password section as shown below. It is better to copy and paste the password to match and then Click on OK to exit.

VBA Project Password Example 1-8

Step 9: Now save the code and then close the VBA and Excel files. To check this, reopen the file. In the VBA window, we will see all the options like Modules in the VBA Project is hidden. To test, click on the plus sign of the VBA Project.

VBA Project Password Example 1-9

Step 10: We will get the password window there. To enter the password which we had chosen. And then click on Ok.

VBA Project Password Example 1-10

Step 11: This would enable the VBA Project with all the options and we will be able to see the code written in the module.

VBA Project Password Example 1-11

Step 12: And if we enter the incorrect password we would then get an incorrect message alert.

Message Alert Example 1-12

Example #2

There is another way to protect the VBA Project using passwords with the help of code. For this, follow the below steps:

Step 1:  In the same module and write the subprocedure.

Code:

Sub VBA_ProjectPW2()

End Sub

VBA Project Password Example 2-1

Step 2: Now write define a variable using DIM as a Variant.

Code:

Sub VBA_ProjectPW2()

Dim PW As Variant

End Sub

VBA Project Password Example 2-2

Step 3: In the defined variable PW we will use the Input Box application and choose the title and message which we would like to see.

Code:

Sub VBA_ProjectPW2()

Dim PW As Variant
PW = Application.InputBox("Enter Password", "Password Protected")

End Sub

VBA Project Password Example 2-3

Step 4: Open the Select Case-Else loop and there write the condition where if the entered password is “Pa$$w0rd123” then we would get the message as secured workbook in select range cell.

Code:

Sub VBA_ProjectPW2()

Dim PW As Variant
PW = Application.InputBox("Enter Password", "Password Protected")
Select Case PW
Case Is = False
Case Is = "Pa$$w0rd123"
Range("A1").Value = "Workbook is secured."
Case Else

End Sub

Excel VBA Project Password Example 2-4

Step 5: And to see if the entered password is incorrect then we would get a message as Incorrect Password.

Code:

Sub VBA_ProjectPW2()

Dim PW As Variant
PW = Application.InputBox("Enter Password", "Password Protected")
Select Case PW
Case Is = False
Case Is = "Pa$$w0rd123"
Range("A1").Value = "Workbook is secured."
Case Else
MsgBox "Incorrect Password"
End Select

End Sub

Incorrect Password Example 2-5

Step 6: Now if we run the code by pressing F5 or the Play Button is mentioned below the menu bar, we would get the Password Protected window where we would enter the password. If the password entered is correct then this window will be closed.

Protected window Example 2-6

Step 7: Once entered, click on Ok.

VBA Project Password Example 2-7

Step 8: We would see the code has run successfully. And the cell A1 would have the message which chose in VBA Code as “Workbook is secured.”

Workbook Example 2-8

Pros of VBA Project Password

  • This is helpful is securing the very confidential code which we probably do not want to show to anyone.
  • VBA Project protected using the methods which we have seen in the above examples is best to secure the code.

Things to Remember

  • Password entered using VBA Project Password can be cracked using the alternate add-ins available and can be downloaded from the internet or Microsoft website.
  • Make sure the password entered is easy to enter, easy to remember. Or else keep the note so that it is not lost. If by any chance the entered password is incorrect then it is hard to recover it.
  • If the excel is not saved in the format of Macro Enable format then the written code will be lost.
  • VBA Project Password is different from the method of protecting the Excel file using Protect Sheet, Protect Workbook available in Review menu bar.

Recommended Articles

This is a guide to the VBA Project Password. Here we discuss how to protect the project code using the password in excel VBA along with practical examples and a downloadable excel template. You can also go through our other suggested articles –

  1. How to Use VBA Login?
  2. VBA Month | Examples With Excel Template
  3. How to Use Create Object Function in VBA Excel?
  4. How to Use VBA IsError Function?
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign In
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Excel Charts
  • Excel Tips
  • All Tutorials
Certification Courses
  • All Courses
  • Excel VBA Course - All in One Bundle
  • VBA Course
  • Excel Data Analysis Course
  • Excel for Marketing Course
  • Excel for Finance Course
  • Excel for HR Training

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

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

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

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

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more