How to Password Protect Your Excel Macro?
Last Updated :
16 Dec, 2021
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.
Implementation:
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 Password Protect an Excel File (Windows and Mac) How to Lock a Excel Sheet with Password - Quick StepsOpen the Excel file Click on File >>Select Info.Protect Workbook >> Choose Encrypt with Password.Set Password >> confirm your password.Keeping your data secure is a priority, especially when handling sensitive information in Exce
9 min read
How to read password protected excel file in R ? In this article, we are going to see how to read password-protected Excel files in R programming language. File in use:Â file Method 1: Using excel.link Package. Here we will use excel.link package to read the file with a password. Installation: install.packages("excel.link") xl.read.file() function
2 min read
How to Protect a Workbook in MS Excel? Every day in school, offices, business sectors or any other field lots of information are there that are required to store for the future use. For anyone, it is very difficult to remember that information for a long time. Earlier data and information are stored in a form of a register, file, or pape
4 min read
How to Manage Passwords using MS Excel? Spreadsheets are another name for Excel sheets. Microsoft Excel was created in 1985 for Apple's Macintosh computer. The data is arranged into rows and columns. Excel sheets containing endless data can be created. There would be n rows and n columns, allowing us to store millions and crores of record
2 min read
How to Password Protect a Google Document Google Docs is a widely used free word processor to create, edit, and share documents with multiple people. In Google Docs, the file gets automatically saved on Google Drive cloud storage. Google Docs also takes care of the person who wants to protect his sensitive or personal documents and wants to
6 min read
How To Password Protect A Google Form Google Forms is an incredibly versatile tool for gathering information, conducting surveys, and planning events. However, when dealing with sensitive data, it's crucial to ensure that your forms are secure and accessible only to intended respondents. By setting up a simple but effective security lay
4 min read