Making an Add-In's Source Code Secure

The Visual Basic source code stored in the modules of a compiled add-in isn't completely protected from being read and copied. If you need complete security for your code, you can protect the structure of the source workbook using the Protection command on the Tools menu. Be sure to use a password when protecting the workbook structure. After protecting the workbook structure, compile the add-in.

When you use this protection technique, you can no longer add the add-in to the list box in the Add-Ins dialog box (Tools menu). If you attempt to add a protected add-in, you'll see an error message telling you that the add-in isn't valid. You can still use the procedures in the add-in by opening the add-in using the Open command (File menu) or by creating a reference to it from a Visual Basic module in another workbook. For more information about these techniques, see "Using an Add-In's Procedures" later in this chapter.

If you must create a secure add-in and it must appear in the Add-Ins dialog box, create two add-ins. The first add-in is the secure one; the second add-in is unprotected and contains a reference to the first add-in — a reference you create using the References dialog box (Tools menu). You can now use the functions in the second add-in, which call the protected code in the first add-in.

Creating completely secure add-in code is a complicated process, and it may add overhead to your add-in, which could reduce performance. Also, you may forget the protection password, in which case you would be unable to add, delete, move, rename, hide, or unhide sheets in the source workbook. For these reasons, you should secure add-ins only when it's absolutely necessary.