How to save VBA code to DLL library?

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.


You can protect your VBA, code by converting it to a password-protected XLA and obfuscating the code. but the password security is weak. Its easy to make the XLA work with all Excel versions.

An easy alternative is to convert to a compiled VB6 Automation addin. Security is good, its easy to convert, it will handle both UDFs and Command addins. But it won't work with Excel 2010-64 or early versions of Excel like XL 2000. You will need a VB6 compiler, which can be hard to find.

A harder alternative is to convert to .NET. If you use one of the many obfuscators then security is reasonable. Performance will be poor unless you use one of the tools that allow .NET access via the XLL interface, such as Excel DNA or Addin Express. 64-bit capability is also available.

If performance and security is critical you would need to convert to a C++ XLL, but this is hard work when coming from VBA.


a) You can save your macro in a separate file and protect it with password but, exist program for "recover password" that can break such protection.

b) While is possible to do a c++ dll, is smart to do instead using visual basic 6 because the syntax is pretty similar to vba. In vb6 you can create a COM component, register it and later add to you excel sheet.