Suppose we want to create unmanaged COM Add-ins with classic VB that should target version 2000 to 2007 of Excel.
One of the first questions we need to answer is whether we should use early or late binding. In my opinion we should, as long as it is feasible, use early binding which of course means in this case that we need to add a reference to the Excel 2000 object library.
Anyway, the most important question is how we can control and manipulate the RibbonX when the COM Add-ins are used with Excel 2007. In more technical terms the question is how to implement the interface for the IRibbonExtensibility in COM Add-ins enabling it to work with both Excel 2007 as well as with previously versions of Excel without causing any additional issues.
One approach would be to include the Office 12 type library file within the project. But this scenario is not doable as the EULA does not permit us to use that file under these circumstances (at least that’s my understanding). Except for that the file size is around 16.5 MB…
A better approach is to copy the part that include the interface for the IRibbonExtensibility from the above file and create a new standalone type library file. It would then only include the necessary technical information to implement the interface in COM Add-ins.
The second blogpost about the subject is available here:
Using IRibbonExtensibility’s type library with COM Add-ins
Before moving on I would like to highlight the following question:
Does the EULA for Microsoft Office 12 allow us to extract information from the MSO.DLL file in order to create standalone type libraries that are used with COM Add-ins?
If the EULA does not allow us then the remaining part of this blog will immediately be removed as soon as the information is received by me from Microsoft. It will then be replaced with the answer for the question.
Creating a standalone type library for IRibbonExtensibility
The following discuss how to retrieve the necessary data from the MSO.DLL file, create the Interface Definition Language (IDL) file, generate the UUID GUID (where GUID is MSFT’s implementation of the UUID standard) and finally how to create the Type Library file (TLB).
# Extract the information about the interface of the IRibbonExtensibility
In order to grab the wanted information we need to have access to the file MSO.DLL which in general should be available in the following location:
C:\Program Files\Common Files\Microsoft Shared\OFFICE12\
Next, we need the utility OLE/COM Object Viewer to view the file (the utility is shipped with both the Microsoft Visual Studio 6.0 as well as Visual Studio.NET 2005).
Click on the “View TypeLib” button in the OLE Viewer and open the above file. The whole content can be copied from the OLE Viewer into a text editor (that can show row numbers). The wanted information is available from line 9580 (where “interface IRibbonUI” is located) and ends at line 9640 (where “} MsoTextDirection;” is located). Save the file under a desirable filename.
# Create the UUID
In order to create a unique UUID (GUID) we need to use the utility GUIDGen.exe. It’s shipped with various Microsoft’s softwares including Visual Studio 6.0 and Visual Studio.NET.
The generated UUID should be added on top in the textfile (see the attached sample file xlRibbon.idl).
Make sure that the textfile is saved and then in the Explorer You can easily change the file extension to IDL.
# Create the TLB file
One of the more common tools to use for this task is the Microsoft Interface Definition Language (MIDL) command line tool. The following command creates the wanted TLB file:
midl /tlb <fullpath-filename.tlb> <fullpath-filename.idl>
# The sample files
The compiled files attached to this blogpost are made available “as is”.
The files xlRibbon.idl and xlRibbon.tlb are packed into one single zip: xlRibbon.zip
# Final comments
I had some major difficulties before I got the MIDL to create the wanted file. Be prepared to spend some time to configure the computer in order to get the MIDL to work properly. On the other hand, the attached files can be used without the need of additional work with them.
By creating a standalone type library for the IRibbonExtensibility interface and adding a reference to the library in COM Add-ins we get a poweful solution that actually can target all the Excel versions between 2000 to 2007. Of course, the compiled files can also be used with the other softwares in the Office suite. I therefore hope that the presented approach don’t violate the terms of the EULA.
The above should be considered as an introduction. Use the above keywords to search for additional information about the utilities that are used here.
In my next blogpost I will discuss (at least, I hope so) how to leverage the created typed library with unmanaged COM Add-ins.