How to protect VBA code in Excel 2010

If you have an EXCEL workbook that includes some VBA code, and you want to hide that code, either to protect your intellectual property or simply to prevent others from messing up your code accidently , then follow these steps:

1. In the Developer tab, Code group, click Visual Basic. This will switch you to VBA development environment.

2. Create your project with the required code.

3. In the VBA development environment, click on the Tools menu and select VBAProject Properties.

The Project Properties window will open.

4. Select the Protection tab.

5. Select the checkbox Lock project for viewing.

6. Enter  Password and Confirm password.

7. Click OK.

8. Save the workbook and then close it so that the password protection takes effect. Next time you open the workbook and try to view the code you will be prompted for the password.

 

How to protect Worksheet elements

To prevent unauthorized users from performing certain worksheet tasks, like formatting cells, deleting rows or inserting rows, follow these steps:

  1. Switch to the worksheet you want to protect.
  1. On the Tools menu, point to Protection, and then click Protect Sheet.
  2. Type a password for the sheet. Then reconfirm the password when asked for that.
  3. In the list: Allow all users of this worksheet to , check the elements which you want the users to have access to. All unchecked items will be protected.

xprotectsheet.gif

Tip:

You can protect the worksheet without entering a password, but in this case anyone can unprotect it. This is only useful if you want to avoid the worksheet being modified accidentally.

Related Links:

How to protect a workbook with a password

Applies to: Excel 2003

How to protect a workbook with a password

To allow only authorized users to view or modify your Excel workbook, you can secure your entire workbook file with a password. Follow the steps below to achieve this goal:

  1. On the File menu, click Save As.
  2. Click Tools.
  3. On the Tools menu, click General Options.

Save Options

  1. If you want users to enter a password before they can view the workbook, type a password in the Password to open box.
  2. If you want users to enter a password before they can save changes to the workbook, type a password in the Password to modify box.
  3. Click OK.
  4. You will be prompted to reenter your password(s) for confirmation.
  5. Confirm your password(s) then click Save.

Tip:

To remove a password from a password-protected workbook (If you have the right to modify of course), then follow the same steps to assign a password i.e.

File –> Save As –> Tools –> General Options

Clear the password(s) –> Click OK –> Click Save.

Notes:

  1. Passwords are case sensitive.
  2. If you are the only one who is allowed to open the workbook, then there is no need to enter the Password to modify.
  3. Make sure that you don’t lose your passwords because there is no easy way to recover them.
  4. This procedure applies to a new workbook as well as an existing workbook for which you want to add a password. In the second case you will be asked if you want to replace the existing file. Click Yes.

Related Links:

How to protect worksheet elements

Applies to: Excel 2003