Open In App

How to Password Protect Your Excel Macro?

Last Updated : 16 Dec, 2021
Like Article

It is a best practice,  to protect the Macro (VBA Code) from other users to edit or view. In this article, we explain to create a simple macro and protect the same “VBA Project” using a password in Excel from other users.


Follow the below steps to protect your excel macro with a password:

Step 1: Open an excel file, to create a simple “hello world” macro.

Step 2: Press Alt + F11 – to open Visual Basic Editor.

Step 3: Click Insert >> Module, which will add a new module as in Img1.

Img 1

Step 4: Type the below code in “code window”.

Sub firstMacro()
MsgBox "Hello World"
End Sub

Step 5: Right-click “VBAProject (Book1)” and then click “VBAProject Properties”.

Step 6: GoTo Protection Tab >> Check “Lock project for viewing” and type your password in both Password and Confirm password input text boxes. Press “OK” 

Step 7: Save your Excel workbook as Excel Macro-Enabled Workbook (*.xlsm) and close

Step 8: Now reopen your excel file.  Press Alt+F8 – to open the Macro dialog box. Select the macro “firstMacro” and click “RUN”.

Step 9: Our macro will pop up below the message box. Close or press OK to hide the message box

Step 10: Press Alt + F11 – to open Visual Basic Editor. Now user cannot see any information in the VBA. 

Step 11: Double click “VBAProject (vbaProtect.xlsm)”, It will ask the user to enter a password.

Step 12: Type your password and press “OK”.  Now user can see all the excel objects and Macro.

At this point we have successfully created a macro in VBA and protected it with a password.

Similar Reads

How to Create a Macro in Excel?
Macros are a set or sequence of instructions that perform as and when required by the user. Initially, a macro is to be recorded. Then the macro is being executed in order to perform a set of a predefined set of commands in Microsoft Excel. Macros save a huge amount of time in performing a set of repetitive actions. To perform a macro, one needs to
2 min read
Assigning Excel Macro to Objects
In Excel, a recorded macro can be assigned to different objects like a shape, graphic, or control note. Instead of running the macro from the required tool in ribbon, we can create these objects to run them easily. They get very handy when multiple macros are there. Individual objects can be created for different macros. In this article, let's disc
3 min read
Excel Personal Macro Workbook
When we create the macros for automation, they can be used for that particular workbook only. We cannot access them outside that workbook in others. Excel Personal Macro Workbook is a hidden workbook in your local system that pops up whenever you open the Excel application. It is a place where all the macros from any workbook can be stored and one
4 min read
How to Record a Macro in Excel
Excel Macro is simply a record button that records a set of actions performed on Excel that can be run multiple times. For example, if you have to format some raw data on a weekly basis you can use a macro to record yourself formatting the data once and let Excel automate the task in the future. it's used to help users save time and avoid performin
11 min read
How to Enable & Run a Macro in Excel? 6 Ways
We can record a macro in Excel or write from scratch in VB Editor. Excel provides different options to run a macro. In this article, we explore four different approaches to running a macro in an Excel application. Even while executing an Excel macro is a straightforward process for seasoned users, it might not be clear to newbies. You will discover
5 min read
What Does the Number in the Addchart2 VBA Macro represent?
A chart or graph can be made in an Excel spreadsheet by using the AddChart2 VBA macro. The desired chart type or style is indicated by the number in the AddChart2 VBA macro. The AddChart2 function uses this number as an input parameter to identify the type of chart or style to be constructed. Each chart type is given a different number. If change t
4 min read
How to Run a Macro Automatically
To run a macro automatically when the workbook opens one must enable the developer's tools in Microsoft Excel. What is a Macro in Excel Macros allows automating repetitive tasks in Microsoft Excel. Some tasks need to be performed multiple times and repetition of all the actions would consume time. In such type of Scenarios, Macros helps in automati
4 min read
How to Mask Password in VBA Excel Input Box?
A combination of integers, strings of characters, or other symbols is used to verify the identity of a user during the authentication process so, that they can access the system. But a password should always remain in a hidden format to prevent it from shoulder spying. Shoulder spying is a practice where a person collects our personal data by spyin
2 min read
Editing Excel Macros in Excel
Excel Macro is a set of actions that can be recorded, saved, used multiple times. This feature saves us a lot of time when dealing with repetitive tasks and huge data sets. We can always make changes to an existing Macro in Excel. There are two ways to record and run macros: Excel Commands Excel Visual Basic for Applications(VBA).1. Copying a Macro
1 min read
Scenario Manager in Excel
A Scenario Manager is a tool in Excel that works on a set of values that Excel saves and can be change up to 32 cells simultaneously. In this article, we will look at how we can use Scenario Manager in Excel. To do so follow the steps below: Step 1: Formatting data. Step 2: Highlight the data in which we want to change by Scenario Manager. Step 3:
1 min read
Article Tags :