How to call a .net assembly in VBA using COM Interop

In this scenario we want to use the .net assembly on the target machine without having access to the GAC and call it in VBA using COM Interop.

 In order to accomplish this we will need to use regasm.exe utility (https://msdn.microsoft.com/en-us/library/tzat5yw6(VS.71).aspx). Once a class is registered, any COM client can use it as though the class were a COM class.

 Use %windir%\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe /codebase abc.DLL which creates a codebase entry in the registry to reference the DLL. The assemblyFile argument that you specify with the /codebase option must be a strong-named assembly https://msdn.microsoft.com/library/en-us/cpguide/html/cpconStrong-NamedAssemblies.asp

 

Make a strong name at command prompt outside bin folder

SN -k abc.snk

Then rebuild the solution. Now give the path where the DLL is present

RegAsm.exe /tlb: abc.tlb abc.DLL

After that use RegAsm.exe /codebase abc.DLL

 

The following articles provide you the detailed steps on how to build COM-Addin

https://support.microsoft.com/kb/302896/en-us/

https://support.microsoft.com/default.aspx?scid=kb;en-us;291392