How to Password Protect Your Excel Macro VBA ?

how-to-password-protect-vba-code

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:

  1. Firstly, Open an excel file, to create a simple “Hello World” macro.
  2. Then, Press Alt + F11 – to open Visual Basic Editor.
  3. Click InsertModule, which will add a new module.
  4. Type the below code in “code window”.
  5. After that, Right-click “VBAProject (Book1)” and then click “VBAProject Properties”.
  6. GoTo Protection Tab → Check “Lock project for viewing” and type your password in both Password and Confirm password input text boxes. Press “OK” 
  7. Then, Save your Excel workbook as Excel Macro-Enabled Workbook (*.xlsm) and close
  8. Now reopen your excel file.  Press Alt+F8 – to open the Macro dialog box. Select the macro “firstMacro” and click “RUN”.
  9. Our macro will pop up below the message box. Close or press OK to hide the message box.
  10. Then, Press Alt + F11 – to open Visual Basic Editor. Now user cannot see any information in the VBA. 
  11. After that, Double click “VBAProject (vbaProtect.xlsm)”, It will ask the user to enter a password.
  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. Remember password otherwise, you need to remove VBA code password.

Conclusion

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.

Leave a Reply

Your email address will not be published.