Home / Protection / Protect VBA

Protect VBA

You can protect you complex VBA scripts from modification and copying through the use of password protection. But yet again the in-built security features offered by Excel can easily be overcome by technically capable users of your spreadsheets. In this post we will demonstrate how to use the standard Excel security to protect you VBA scripts and macros.


Step 1 – Open the VB Script Editor

Open the the Workbook that contains the VBA scripts that are to be protected. From the Tools > VBA Project Properties. Now specify a password for select ‘Lock project for viewing’. Make sure you remember the password and then click OK, finally save the workbook and exit.


Step 2 – Now try and Open the protected VB script

Now re-open the Workbook and access the VB script editor. When you try and open the VB script the password is requested. If you don’t supply it then access to the VB script is denied.


Other Options – VBA Scrambling

If you really need to protect your VB script from easy copying and re-use one of the best methods is to perform some form of scrambling routine so that you VB script essentially becomes unreadable or very hard to follow. That way any user that attempts to simply copy your VB script cannot follow your logic or modify the script for other purposes.

You can scramble you code manually or you can purchase products to perform scrambling of your VB script. One of the best products we have found that can quickly and effectively scramble your VB script has been developed by the Excel developers at XLAutomation. Their product VBA Scrambler offers automated scrambling for VB script. Click Here to find out more about VBA Scrambler.

Before Scrambling

After Scrambling

If you have a question on this post for the Excel Help Desk team or have something you would like to share on this topic then please leave a comment

About Excel Help Desk

Check Also

How to Lock and Protect all Worksheets in a Workbook

In this post we provide a macro that can be used to automatically apply Worksheet Protection to single Worksheet, some Worksheets or all Worksheets in a Workbook. In future posts we will provide an macro that will Disable Worksheet Protection.

4 comments

  1. Thanks for this. It works.

  2. Hello! I followed Step 1 exactly and it will not save my password. Every time I re-open it and try to access the VBE, I am not prompted for a password and am able to see all VBE contents. I am using Windows 7, Office 2010. Any suggestions? This is very frustrating!

    • Hi Karen,
      The steps outlined should work…..can we try them one more time.

      1. Open the workbook that needs protection

      2. Open the VBE and access the Tools > VBA Project Properties

      3. Click on the Protection tab

      4. Specify a Password and Confirm the Password

      5. Check the box “Lock for Viewing”

      6. Press OK, then save the workbook and exit.

      7. Lastly access the workbook and try to view the VBA modules you have in place, you should receive a password request.

      If this doesn’t work we may look into the actual workbook you are attempting to apply the password to.
      Regards
      Excel Help Desk Support Team

    • Hi karen,

      After doing all step , just close the workbook & reopen it .
      It is asking for the password when u trying to open the VBA code.
      Its working for me on Win-7 with office 2010.