Document

4 Ways to Protect VBA (Visual Basic for Applications) Code

The VBA code that you write is the heart and soul of your spreadsheet. Protecting VBA code is something that should be done to make sure your code doesn’t get stolen or used without you knowing. This post will cover some different ways of protecting your VBA code so that only YOU can easily access it.

Why Should You Care About Protecting VBA Code?

VBA is a macro language that can be used to create automated tasks or actions in Excel, Word, PowerPoint. There are several reasons that you should protect your VBA code:

  • To protect your VBA code from being accidentally changed. VBA code is a powerful tool for Excel users, but it can also be a source of frustration for those who don’t use it. If you don’t secure the VBA with a password, then others using your workbook can access the code and make changes to it without knowing what they’re actually doing. You don’t want to debug your VBA code because it can be painful—might take hours to figure out why and then even more time!
  • To protect your intellectual property. VBA code can be very valuable to some companies. If someone else accesses your spreadsheet and copies the functionality that you use, then they could potentially pass it off as their own work and sell it to a lot of companies. Protect your valuable source code with security measures. Don’t make it easy for anyone to steal or copy.
  • To protect yourself from people using your work. If you have a valuable piece of VBA code that’s making your work easier or more efficient, then you may want to protect it for personal use only.

It’s important to note that there are several different ways of protecting your VBA code, but not all of them protect your code in the same way. It’s up to you and what you think is best for your needs.

#1 Password Protect VBA Code Within Excel Using VBAProject Tool

This part explains how you can use VBA project protection settings to protect your VBA code from prying eyes and tampering hands on some level.

  • Security level: Weak; There are tools such as VBA Password Remover which can be used to unlock the password in minutes;
  • Difficulty: Easy;
  • Cost: Free;

Step 1. Select “Visual Basic” from the “Developer” menu in Excel.

Open Visual Basic Panel from Excel Developer Tab

Step 2. To lock down your VBA project, click “Tools” in the bar and then select “VBAProject Properties”.

Select VBAProject Properties to Set Password

After clicking on this menu item, you should see the following dialogue box:

The Main Interface of VBAProject Properties

The “General” tab is selected by default, but click on the “Protection” tab.

Step 3. Check “Lock project for viewing” and then type in your password twice into both of these boxes and hit “OK”.

Lock VBA Project for Viewing and Set Password to Protect VBA Code

Step 4. Save it and reopen the Excel file. You’ll be able to tell whether VBA password protection was properly enabled by double-clicking your VBA project. When you protect your VBA project with a password, it will prevent anyone from accidentally modifying.

Password Needed for Viewing VBA Code

#2 Use VBA Obfuscation to Protect Your Macro Code

VBA obfuscation is the art of making your VBA code unreadable but still functional. It modifies your existing macros with multiple levels of obfuscation which makes it difficult to understand the underlying logic. Advanced VBA obfuscators use a number of advanced obfuscation techniques, making reverse tracing and recovery considerably more challenging.

  • Security level: Medium; Someone will still be able to take the time and spend enough resources to recover the code;
  • Difficulty: Moderate; Depending on the level;
  • Cost: Free VBA Obfuscator/Premium;

You can use VBA obfuscation in tandem with the #1 technique, which is to first obscure and then secure the module with a password. Please keep in mind that the obfuscation is irreversible, so make a backup of the source file before proceeding. Also remember that the obfuscated code can’t be guaranteed to execute without faults. Please test it thoroughly before releasing it. Use a single part of the project to obfuscate. After the first module obfuscation test is successful, move on to the second.

#3 Convert VBA Code to Dynamic-Link Library (DLL)

Compilers such as Visual C++ and Visual Basic produce applications that are difficult to crack. This is due to the fact that the code is compiled into executable files or dynamic link library files. So we can also compile the VBA code into a dynamic link library file and then use it in Excel.

  • Security level: High;
  • Difficulty: Moderate;
  • Cost: Free;

This method of protection is highly recommended, but it isn’t 100% guaranteed. To learn how to compile, see the instructions at VbaCompiler.com: 10 steps to compile VBA code into native Windows DLL.

Excel File VBA Code Compilation Done Successfully with VbaCompiler for Excel

#4 Convert VBA to C or C++

Translating your macros to C or C++ is harder to reverse engineer than VBA. If you want to protect your code, this is the best way.

  • Security level: Highest; It’s nearly impossible to get the code without the rights; But again, it isn’t 100% guaranteed;
  • Difficulty: Complicated and time-consuming; Because VBA and C/C++ are such different languages, it’s more difficult since you’ll have to invest a lot of effort.

Conclusion

Using macros is a great way to streamline the development of advanced functions. Unfortunately, this puts your code at risk of being stolen or copied by others. The article discusses methods you can use to prevent other users from stealing or tampering with your VBA code. Please note that the VBA code protections are not bulletproof security, but it does provide some protection against casual attackers.

Susanna

Susanna is the content manager and writer of Filelem. She has been an experienced editor and book layout designer for many years, and interested in trying and testing various productivity software. She is also a huge fan of Kindle, who has been using Kindle Touch for nearly 7 years and carrying Kindle almost wherever she goes. Not long ago the device was at the end of its life so Susanna happily bought a Kindle Oasis.

Related Articles

Back to top button