![]() |
||||
Traditionally add-ins for the 32-bit VBA editor of Microsoft Office were created with Visual Basic 6.0, which can generate 32-bit COM (ActiveX) DLLs. However, the VBA editor of the 64-bit version of Microsoft Office 2010 only supports 64-bit COM add-ins, so it is not possible to create add-ins for that version using Visual Basic 6.0. It is possible to create an add-in for the 64-bit VBA editor of Office (and for the 32-bit VBA editor) using Visual Studio .NET and the .NET Framework, since .NET dlls can be 32-bit or 64-bit and both can be registered for COM-Interop. The approach is the following (as explained in the article HOWTO: Create an add-in for the VBA editor (32-bit or 64-bit) of Office with Visual Studio .NET):
This article explains how to get the required extensibility assemblies to be referenced by the Visual Studio .NET project. More informationThe COM type libraries used by add-ins of the VBA editor of Microsoft Office are the following:
Since those are COM (ActiveX) type libraries, to reference them from a .NET Class Library project Interop assemblies are required. An Interop assembly is a .NET assembly that allows a .NET application or library to access a COM (ActiveX) type library (acting as a wrapper). There are two kind of interop assemblies:
Microsoft has provided PIAs for some Office type libraries:
But the approach used here is to generate private Interop assemblies for all those COM type libraries. This is because if the PIAs are not on the target machine, the setup would have to install them in the Global Assembly Cache (GAC) and that requires admin rights, while private interop assemblies can reside on the same folder than the add-in dll, and that folder can be a per-user folder which doesn't required admin rights. Note: if you use .NET Framework 4.0 or higher, you can embed interop typess and deploying the interop assemblies would not be required. However, if the user doesn't have .NET Framework 4.0 your setup would have to install it. Using .NET Framework 2.0 is much more likely that this step of the setup is not required. To generate the Interop Assemblies you can use the .bat script below. You will need the to adjust the following names before executing the script:
Note 1: the ^ character at the end of each line is the line-continuation character in .bat script files. It is used for formatting purposes. Note 2: it is normal to get the following warnings executing the script:
but at the end of each execution you should get a success message and a file with the name MyCompany.Interop.<filename>dll: Type library imported to <path>\MyCompany.Interop.<filename>dll
@ECHO OFF "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\tlbimp.exe" ^ "C:\Program Files (x86)\Common Files\DESIGNER\MSADDNDR.DLL" ^ /out:"MyCompany.Interop.Extensibility.dll" ^ /keyfile:"C:\mycompany.snk" ^ /strictref:nopia /nologo /asmversion:1.0.0.0 /sysarray PAUSE CLS "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\tlbimp.exe" ^ "C:\windows\syswow64\stdole2.tlb" ^ /out:MyCompany.Interop.Stdole.dll ^ /keyfile:"C:\mycompany.snk" ^ /strictref:nopia /nologo /asmversion:1.0.0.0 PAUSE CLS "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\tlbimp.exe" ^ "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE12\mso.dll" ^ /out:MyCompany.Interop.Office12.dll ^ /keyfile:"C:\mycompany.snk" ^ /strictref:nopia /nologo /asmversion:1.0.0.0 ^ /reference:MyCompany.Interop.Stdole.dll PAUSE CLS "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\tlbimp.exe" ^ "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb" ^ /out:MyCompany.Interop.VBAExtensibility.dll ^ /keyfile:"C:\mycompany.snk" ^ /strictref:nopia /nologo /asmversion:1.0.0.0 ^ /reference:MyCompany.Interop.Office12.dll PAUSE Related articles
|
| Copyright © 2000-2013 MZTools Software. All Rights Reserved. Legal Notice |