This article will teach you How to Password Protect VBA Code in Excel Macro with VBA so that you can secure your Excel macro workbook.
It is recommended to protect the macro (VBA code) against any modification or viewing by other users. In this article, we will explain how to create a simple macro and protect the same “VBA project” from other users with a password in Excel.
How to Password Protect an Excel Macro VBA Code?
Follow the below steps to protect your excel macro with a password, learn how to password protect VBA code in Excel Macro:
- Firstly, Open an excel file, to create a simple “Hello World” macro.
- Then, Press Alt + F11 – to open Visual Basic Editor.
- Click Insert → Module, which will add a new module.
- Type the below code in “code window”.
- After that, Right-click “VBAProject (Book1)” and then click “VBAProject Properties”.
- GoTo Protection Tab → Check “Lock project for viewing” and type your password in both Password and Confirm password input text boxes. Press “OK”
- Then, Save your Excel workbook as Excel Macro-Enabled Workbook (*.xlsm) and close
- Now reopen your excel file. Press Alt+F8 – to open the Macro dialog box. Select the macro “firstMacro” and click “RUN”.
- Our macro will pop up below the message box. Close or press OK to hide the message box.
- Then, Press Alt + F11 – to open Visual Basic Editor. Now user cannot see any information in the VBA.
- After that, Double click “VBAProject (vbaProtect.xlsm)”, It will ask the user to enter a password.
- 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. Remember password otherwise, you need to remove VBA code password.
By creating a macro in Microsoft Excel, you can schedule automatic tasks in a spreadsheet or template that can contain multiple commands or functions for easy access and use. Once these macros are in the spreadsheet, anyone using the sheet can change them unless you protect the macros with the password system provided by Microsoft. To protect yourself from the list of macros and to allow private use, you can completely hide the macros from the user view.