Search code examples
.netvb.netexcelcomcom-interop

Deploying an DLL (COM object) to Excel vba reference


I have developed (VB.Net) a DLL in VS2010 to use in Excel (Windows 7 64 bit with 32 bit Office 2010)

The Class Library has both 'Make assembly COM-Visible' & 'Register for COM interop' checked.

The Target CPU is set to x86 using .Net 4.0 Framework.

When I build this on my development machine the DLL is available in Excel vba to be selected as a Reference and the Excel executes the DLL correctly.

The problem comes when I attempt to deploy the DLL to other Window 7 machines.

I have successfully(?) registered the DLL using the following command line (as an Administrator)

C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Program Files\CompanyName\XXX_DLL.dll"

However the DLL does not appear in Excel vba to be selected as a Reference.

Where have I made a mistake / what am I doing wrong?

Many Thanks.


Solution

  • You need to add the /codebase argument to the call to RegAsm if you wish to register a COM assembly that is not in the GAC

    Try this:

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Program Files\CompanyName\XXX_DLL.dll" /codebase

    Documentation for RegAsm

    You will also need to sign your assembly with a strong name.

    Note that the 'Register for COM Interop' only applies to the machine on which the build takes place (avoids you have to run RegAsm after every build. It has not effect when deployed.