VSTO & .NET & Excel

December 12, 2006

Creating a standalone type library for IRibbonExtensibility

Filed under: .NET & Excel, COM Add-ins — Dennis M Wallentin @ 11:41 pm

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

The question
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.

Kind regards,


  1. Nice, Dennis. I too hope that it doesn’t violate the terms of the EULA, as we need a way to create files that can be easily used across all these versions.


    Comment by Ken Puls — December 13, 2006 @ 6:27 pm

  2. Ken,

    Thanks for Your comment.

    The question also target situations where we want to create managed COM Add-ins across the mentioned versions.

    Kind regards,

    Comment by Dennis Wallentin — December 13, 2006 @ 6:38 pm

  3. This is truly an outstanding article Dennis. Very badly needed, and very well done. 🙂

    I can’t imagine why this would violate the EULA, though, would it? Is there a reason for your suspicions here, or just a fear?

    Although, I suppose that it could possibly violate the specifics of the EULA somewhere (I’m no lawyer!) it certainly would seem withiin the spirit of what MSFT would want to empower their clients (those licensing MS Office) and programmers developing solutions for those clients to be able to do. Just my 2c though!

    Comment by Mike Rosenblum — December 14, 2006 @ 4:21 am

  4. Ok, thinking about this a bit further…

    I think I might see what you are getting at, about extracting only part of the Office 12 typelib. Of course, this piece is not of any use to any client that does not have Office 12 installed, so, again, in spirit, I don’t see a problem. But I suppose that it is possible MSFT perhaps might not want programmers “mucking around”? I don’t know.

    If this is an EULA issue then I guess one would have to make two separate solutions: one targeting the Excel 2003 typlib and the other targeting the Excel 2007 typelib.

    Comment by Mike Rosenblum — December 14, 2006 @ 4:40 am

  5. Mike,

    Thanks for Your kind comments.

    I’m not qualified to interpretate the EULA and in order to avoid any misunderstanding I thought that it would be appropiated to raise the question.

    If I understand it correctly this is the first time we need to use an approach like the suggested one in order to get a single Add-in to work with the mentioned versions. So for me it’s a question of policy which will be a guideline for future situations like this one (if necessary).

    Kind regards,

    Comment by Dennis Wallentin — December 14, 2006 @ 9:31 am

  6. Hi Dennis,
    Great article!!

    Can we not define the IRibbonExtensibility and other related interfaces to the project in a .cs file? Preserving their GUIDs.


    Comment by Abhimanyu Sirohi — May 4, 2009 @ 10:37 am

    • Hi,

      Thanks for Your kind words. I’m not sure how that approach would look like. Can You develop it further?

      Kind regards,

      Comment by Dennis Wallentin — May 4, 2009 @ 11:42 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: