MrExcel Publishing
Your One Stop for Excel Tips & Solutions

password protect vb code


Posted by steven scaife on October 25, 2001 6:59 AM

How do I password protect my vb code so that no one can access it.

I have looked through the help file but can't locate anything useful to help me.

thanks in advance if you can help me


Posted by Tom Urtis on October 25, 2001 7:33 AM

Here's how to do it

Here's how to protect VB modules:

(1) Go into the VBE (Tools > Macro > Visual Basic Editor).

(2) In the Project Explorer window (typically the left vertical pane in the VBE), select by highlighting the VBA Project you want to protect. This will be your workbook, in bold type, with the syntax VBAProject (YourFileName.xls).

(3) Click on Tools > VBAProject Properties, select the Protection tab, select "Lock project for viewing", then enter & confirm your password in the fields provided, and click OK.

When you close your workbook and open it next time, your modules will be password protected.

Tom Urtis

Posted by beerman on October 26, 2001 7:58 AM

In the project explorer right click on the userform of item you wish to protect and select VBAProject Properties... On the Protection Tab you can enter your password. After you save the workbook it is protected. I know it works for userforms but it should work for worksheets as well. Hope that helps!
-------------------------------------------------