EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home VBA VBA Resources VBA Tips VBA Project Password
 

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.

Watch our Demo Courses and Videos

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

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.

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:

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?

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA

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

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

EDUCBA

Download VBA Project Password Excel Template

EDUCBA
Watch our Demo Courses and Videos

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

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

Forgot Password?

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Limited Time Offer! - ENROLL NOW