How to save VBA code to DLL library?

Skuta picture Skuta · Feb 8, 2011 · Viewed 24.3k times · Source

For security purpose, I want to save my macros from VBA in Excel workbook to DLL library file I'd be calling from the file later.

This way it is possible to deploy any version of my macros to company's PCs but noone would ever see the real code behind it.

How is this possible? I've read on converting to C++ and creating DLL. Is there any step-by-step solution for this?

Answer

Chris Rae picture Chris Rae · Feb 8, 2011

First off, let me warn you against this in general. We did this once with a corporate app and the time it took to port was approximately the same as the time it took to write the app originally. A step-by-step guide won't exist for this because you're basically rewriting the app from scratch.

Secondly, not everything your Excel VBA can do is necessarily available in COM, or XLL. The events available are different; in the case of XLL there are entirely new structures to use for all of the data types. In COM there are no UDFs; in XLL there are no macro actions. You will no longer be able to attach code to worksheets (only Excel sessions) and the install procedures are much more complex. I would spent a long time researching what your VBA does exactly before embarking down one particular path.

It depends how large your app is, but I would encourage you to invest the money in getting watertight licenses drawn up and doing some basic code obfuscation (as per the original comments) rather than starting from scratch with a different architecture.