PW = Application.InputBox("Enter Password", "Password Protected") 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. Step 2: Now write define a variable using DIM as a Variant. Step 1: In the same module and write the subprocedure. There is another way to protect the VBA Project using passwords with the help of code.
Step 12: And if we enter the incorrect password we would then get an incorrect message alert.
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. To enter the password which we had chosen. Step 10: We will get the password window there.
To test, click on the plus sign of the VBA Project. In the VBA window, we will see all the options like Modules in the VBA Project is hidden.
Step 9: Now save the code and then close the VBA and Excel files. It is better to copy and paste the password to match and then Click on OK to exit. The password should be the same in Password and Confirm Password section as shown below. Step 8: We have chosen the password as “ Pa$$w0rd123” in the combination of Upper case, lower case, special character, and numbers.
Preferably the password should be strong enough not be cracked easily by anyone. Step 7: Now in the Protection tab’s Password and Confirm password section write the password which you want. Step 6: We will then get the Project Properties as shown below. Now to protect the VBA Project with a password, go to Tools menu option and select VBA Project properties as shown below. We would notice that the code has run without any error. Step 5: To test this, we would run this code by pressing F5 or Play Button is mentioned below the menu bar. This is the simplest code that we protect using the VBA Project password. Step 4: And last to close the code, use Debug print to print the value whichever could be stored in variable A.
In the complete lesson 2 you will learn how to add any type of components and how to remove, import, export and manage them from the Project window.Ĭlose the VBE and close Excel without saving anything.Step 3: Use DIM to define a variable as an Integer. You can export and save these modules to be used later in other workbook. Modules are folders in which you save one or many of your macros. Userforms are dialog windows (see example image below) that you develop to communicate with the users of your Excel programs and ask them to supply information or make choices. The workbook " vba-tutorial-editor.xls " has 7 sheets, two userforms, two modules plus the "ThisWorkbook" object. In the picture above you can see that the VBAProject named "Book1.xls" has 3 sheets and ThisWorkbook. If you have purchased and downloaded the course on Excel Macros and opened the Excel file " vba-tutorial-editor.xls " plus a new workbook you will see this:
Notice that the worksheets are sorted alphabetically in the Project window even if they are not in the workbook.
Step 4: Using the "ALT/F11" key, go back to the Visual Basic Editor and see that a sheet has been added to the workbook. Step 3: In the dialog window that appears, click on "OK". Right-click on the tab of Sheet2 and select "Insert". Step 1: Using the ALT/F11 key go back to Excel. We will now complete a brief exercise to learn how easy it is to work within the Project Window.Įxercise 2 (Create your first macro and use it) As we will see later in lesson 9 on events "ThisWorkbook" is a component in which you will store the macros ( also called VBA procedures) that should start automatically when the workbook is opened. You can use the + and - signs to show the details.Ī new Excel workbook includes three sheets and another component named "ThisWorkbook". Use ALT/F11 to open the Visual Basic Editor as you learned in lesson 1.Īs you can see, the Project window shows you all the workbooks that are open ("Book1") in the example below) and their components. Note: Print this page, open Excel and a open a new workbook. Lesson 2 on Excel macros (VBA): The Project Window in the VBE of Excel
Here is a sample of what you will find in lesson 2 of the downloadable Tutorial on Excel macros