How to Password Protect Your Excel Macro?
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.
Please Login to comment...