12
readers helped!

This helped me

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.

For unprotection and removal of VBA passwords, see this article.

Method 1
Method 1 of 3:

Secure VBA Code with a Password

  1. Step 1 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.)
    • Select "Project Properties" in the "Tool" menu within the Visual Basic Editor.
      Step 1 Open the Visual Basic Editor, usually found under "Macro" in the "Tools" menu.
  2. Step 2 Go to the "Protection" tab.
  3. Step 3 Select the "Lock Project for Viewing" check box.
    If you don't check this box, you won't hide your code.
  4. How.com.vn English: Step 4 Create and confirm your desired password in the indicated boxes.
  5. How.com.vn English: Step 5 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.)
    Advertisement
Method 2
Method 2 of 3:

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

  1. Step 1 Go to the "Database Tools" tab.
  2. Step 2 Find the "Database Tools" group.
  3. Step 3 Select "Make ACCDE."
  4. How.com.vn English: Step 4 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.
    Advertisement
Method 3
Method 3 of 3:

Protect Your VBA Code by Making an Add-In

  1. How.com.vn English: Step 1 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. How.com.vn English: Step 2 Copy your VBA code into the Visual Basic Editor of that empty file.
  3. Step 3 Open the "Macros" window, usually stored under "Tools."
  4. How.com.vn English: Step 4 Test your code again, which debugs it.
  5. How.com.vn English: Step 5 Remove anything added to the empty file by your test.
  6. How.com.vn English: Step 6 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. How.com.vn English: Step 7 Compile your code.
    (In the Visual Basic Editor, look under the "Debug" menu and select "Compile VBA Project.")
  8. How.com.vn English: Step 8 Save a copy of the file in a standard file type.
  9. Step 9 Go to "Tools" in the Visual Basic Editor, then select "Project Properties."
  10. Step 10 Select the "Protection" tab.
  11. Step 11 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. Step 12 Open the "Save As�" or "Save a Copy" dialog box.
  13. How.com.vn English: Step 13 Access the drop-down menu and change the file type to the appropriate type of add-in.
    • 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.)
    • Save a Microsoft Excel add-in as an XLA file.
    • 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.)
    • 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. How.com.vn English: Step 14 Quit and reopen Microsoft Office.
    Your add-ins should now be usable.
    Advertisement

Community Q&A

Search
Add New Question
  • Question
    What if I forgot my password to open the VBA project? Will it become unrecoverable?
    How.com.vn English: Sylvia Saltaformajo
    Sylvia Saltaformajo
    Community Answer
    Unfortunately yes, you won't be able to recover it using VBA editor you used to set the password. However, VBA passwords are easily removed by password recovery software such as Password-Find, Password Lastic, Rixler, etc, you can find it online.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit

      Advertisement

      Tips

      • If you can't find the VBA Editor or Add-In Manager, make sure it is installed on your computer. If not, you'll probably need to access your Office suite installation disks to install the necessary programs.
      • Your specific settings and setup for Microsoft Office can affect where different functions are located in each program. If you can't find a function, try running a quick "Help" search for the function name.
      Advertisement

      About this article

      How.com.vn is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 17 people, some anonymous, worked to edit and improve it over time. This article has been viewed 255,402 times.
      How helpful is this?
      Co-authors: 17
      Updated: February 8, 2024
      Views: 255,402
      Thanks to all authors for creating a page that has been read 255,402 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement