How to Protect VBA Code

Microsoft's Visual Basic for Applications (VBA) is the standard language for writing programs to automate functions and tasks in Microsoft Office. Understand how to protect VBA code so others can't sabotage or steal your macros. Open the...

Method 1 of 3:

Secure VBA Code with a Password

  1. Picture 1 of How to Protect VBA Code
    Open the Visual Basic Editor, usually found under "Macro" in the "Tools" menu. (In Access, you may need to be in the database window to reach the editor, depending on your computer set-up.)
    1. Select "Project Properties" in the "Tool" menu within the Visual Basic Editor.
      Picture 2 of How to Protect VBA Code
  2. Picture 3 of How to Protect VBA Code
    Go to the "Protection" tab.
  3. Picture 4 of How to Protect VBA Code
    Select the "Lock Project for Viewing" check box. If you don't check this box, you won't hide your code.
  4. Picture 5 of How to Protect VBA Code
    Create and confirm your desired password in the indicated boxes.
  5. Picture 6 of How to Protect VBA Code
    Save, close, and reopen your workbook for the protection to take effect. (In Microsoft Excel 2007 and later, you may need to save as an XLSM file for your code to work.)
Method 2 of 3:

Hide VBA Code in a Read-Only File with Access 2007

  1. Picture 7 of How to Protect VBA Code
    Go to the "Database Tools" tab.
  2. Picture 8 of How to Protect VBA Code
    Find the "Database Tools" group.
  3. Picture 9 of How to Protect VBA Code
    Select "Make ACCDE."
  4. Picture 10 of How to Protect VBA Code
    Save the ACCDE file with a separate name from the original file. That ACCDE file is a read-only file type, so you need to keep the original file, too, to be able to make any changes.
Method 3 of 3:

Protect Your VBA Code by Making an Add-In

  1. Picture 11 of How to Protect VBA Code
    Create an empty Office file of the type that will use your code. (For example, if your code works with MS Excel, create an Excel file.)
  2. Picture 12 of How to Protect VBA Code
    Copy your VBA code into the Visual Basic Editor of that empty file.
  3. Picture 13 of How to Protect VBA Code
    Open the "Macros" window, usually stored under "Tools."
  4. Picture 14 of How to Protect VBA Code
    Test your code again, which debugs it.
  5. Picture 15 of How to Protect VBA Code
    Remove anything added to the empty file by your test.
  6. Picture 16 of How to Protect VBA Code
    Add a description to the macro that will run in your add-in. (You may need to select macro "Options" to be able to insert the description.)
  7. Picture 17 of How to Protect VBA Code
    Compile your code. (In the Visual Basic Editor, look under the "Debug" menu and select "Compile VBA Project.")
  8. Picture 18 of How to Protect VBA Code
    Save a copy of the file in a standard file type.
  9. Picture 19 of How to Protect VBA Code
    Go to "Tools" in the Visual Basic Editor, then select "Project Properties."
  10. Picture 20 of How to Protect VBA Code
    Select the "Protection" tab.
  11. Picture 21 of How to Protect VBA Code
    Activate the "Lock Project for Viewing" check box. (You may also need to set a password, depending on the specific file type you're working with and your settings for MS Office and your computer.)
  12. Picture 22 of How to Protect VBA Code
    Open the "Save As�" or "Save a Copy" dialog box.
  13. Picture 23 of How to Protect VBA Code
    Access the drop-down menu and change the file type to the appropriate type of add-in.
    1. Save a Microsoft Word add-in as a DOT file, a document template. (If you want the add-in to run when you start Word, save it in the Word Startup folder.)
    2. Save a Microsoft Excel add-in as an XLA file.
    3. Save a Microsoft Access add-in as a MDE file, which will protect the VBA code. (Microsoft Access add-ins can also be saved as MDA files, but this doesn't hide the code.)
    4. Save a Microsoft PowerPoint add-in as a PPA file which will hide the VBA code and leave it unable for anyone other than you to access it or edit it.
  14. Picture 24 of How to Protect VBA Code
    Quit and reopen Microsoft Office. Your add-ins should now be usable.
Update 05 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile