How to load different ribbon XML for word 2007 and 2010? RRS feed

  • Question

  • I need to load and show different ribbon in word 2007 and word 2010 interface, but not able to understand how to proceed :( ...

    I am using ribbon XML way to load ribbon interface in my addin. The ribbon namespace is office 2010 compliant and thus I'm afraid it might not work in 2007.

    I m using this:

    <customUI onLoad="Ribbon_Load" xmlns="">

    I used this URL since my addin also creates Tab in backStage interface which is not supported in 2007 interface. So i was thinking to create 2 ribbon XML and load them conditionally but I am unable to load XML as GetCustomUI() function only provides ribbonID as argument which has same value for 2007 and 2010 :( .. plz help ...


    Monday, September 5, 2011 8:03 AM


All replies

  • anyone ... any suggestions ?
    Monday, September 5, 2011 1:48 PM
  • Interesting, that I'm only seeing this now. I've been in and out of the forums for a few hours, today...

    The ID for the Ribbon is a static value that depends on the application (or, with Outlook, the Outlook window) you're targeting.

    You'll find a complete list in Part 3 of the "Customizing the 2007 Office Fluent Ribbon for Developers " article:

    For Word it appears to be: "Microsoft.Word.Document"

    Cindy Meister, VSTO/Word MVP
    • Marked as answer by VChaddha Tuesday, September 6, 2011 10:27 AM
    Monday, September 5, 2011 3:43 PM
  • Thnks for the reply :-) .. i was eagarly awaiting some suggestions :P ... 


    Yes that is my concern and confusion. since this is the function that returns Ribbon XML dynamically:


        Public Function GetCustomUI(ByVal ribbonID As StringAs String Implements Office.IRibbonExtensibility.GetCustomUI
            Return GetResourceText("SharedRibbonXML2010.xml")
        End Function



    But here I could not find any way to determine if Host Application is Word 2007 or Word 2010 ?

    RibbonID  returns: "Microsoft.Word.Document"


    How can I determine if ribbon is to be loaded for Word 2007 or Word 2010, I do not want to miss out on New Ribbon enhancements for Office 2010 :( ...


    • Edited by VChaddha Monday, September 5, 2011 4:07 PM
    Monday, September 5, 2011 4:06 PM
  • <<How can I determine if ribbon is to be loaded for Word 2007 or Word 2010, I do not want to miss out on New Ribbon enhancements for Office 2010 :( ...>>

    You should be able to test Globals.ThisAddin.Application.InnerObject.Version to get the version number of Word in which the add-in is loading. "12"-something will be 2007; "14"-something will be 2010.

    Cindy Meister, VSTO/Word MVP
    Monday, September 5, 2011 4:35 PM
  • Thnx for the insight .. I tried doing this:


            If Globals.WordAddIn.Application IsNot Nothing Then
                Dim majorVersionString As String = Globals.WordAddIn.Application.Version.Split(New Char() {"."c})(0)
                majorVersion = Convert.ToInt32(majorVersionString)
            End If


    This is my Ribbon Initializer function:


        Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
            Dim majorVersion As Integer = -1
            If Globals.WordAddIn.Application IsNot Nothing Then
                Dim majorVersionString As String = Globals.WordAddIn.Application.Version.Split(New Char() {"."c})(0)
                majorVersion = Convert.ToInt32(majorVersionString)
            End If
            Return New SharedLib.SharedRibbonXML(majorVersion)
        End Function


    Problem now is


    This line is causing Exception, may be due to some hidden fact that we cannot read Addin Application in this particular function so I'm unable to find the Version of application ...

    The documentation here says we can use our own conditonal login in this function:

    But it doesn't work for me since my condition must return Version info :( ... any ideas ..

    I can think of other last idea is to use Registry to find version .. but do u feel reading from Registry is Optimum solution to read Office Installed Info?

    Monday, September 5, 2011 6:01 PM
  • <<


    No, literally what I wrote: Globals.ThisAddin.Application.InnerObject.Version

    Cindy Meister, VSTO/Word MVP
    Tuesday, September 6, 2011 6:36 AM
  • Hmm ... :-) .. I understand your point ... sorry but I missed to mention that I've my Ribbon Files in a Separate Library project and not the Word VSTO Project. I needed to share Ribbon with multiple office projects (I've multiple VSTO Projects in single Solutions), and due to this, the Globals.ThisAddin context is coming in as NOTHING in Ribbon Initializer Function CreateRibbonExtensibilityObject.
    Tuesday, September 6, 2011 7:17 AM
  • Of course I've no idea how your project is built, then, and can't give you a definitive answers.

    But I'm assuming something must be intializing this separate library, a constructor of some kind? In that case, pass the version information to the constructor. Or have the add-in put the information somewhere where the library can find it.

    Cindy Meister, VSTO/Word MVP
    Tuesday, September 6, 2011 7:27 AM
  • Ok here is the layout:

    VS 2010 Solution

    |-- Class Library Project (Ribbon XML and Ribbon Class file exist here)

    |-- WordAddIn VSTO Project


    In WordAddIn project this is my Initialization code:


    Public Class WordAddIn
        Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
            'Globals.WordAddIn --> If used here causing Exception - NullReference Error
    Return New SharedLib.UI.SharedRibbonXML()     End Function     Private Sub ThisAddIn_Startup() Handles Me.Startup         If Globals.WordAddIn.Application.ActiveDocument IsNot Nothing Then             Dim majorVersionString As String = Globals.WordAddIn.Application.Version.Split(New Char() {"."c})(0)             Dim majorVersion As Integer = Convert.ToInt32(majorVersionString)             If majorVersion >= 14 Then             ElseIf majorVersion >= 12 Then             End If         End If     End Sub     Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown    End Sub End Class

    <Runtime.InteropServices.ComVisible(True)> _
    Public Class SharedRibbonXML
        Implements Office.IRibbonExtensibility
        Private ribbon As Office.IRibbonUI
        Public Sub New()
        End Sub
        Public Function GetCustomUI(ByVal ribbonID As StringAs String Implements Office.IRibbonExtensibility.GetCustomUI
            ' Globals.WordAddIn (is inascessible here as this is seperate Project)
            Return My.Resources.SharedRibbonXML2010
            '	OR
            '	Return My.Resources.SharedRibbonXML2007 (if I am able to detect it is Office 2007)
        End Function
        'Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1.
        Public Sub Ribbon_Load(ByVal ribbonUI As Office.IRibbonUI)
            Me.ribbon = ribbonUI
        End Sub
    End Class





    Tuesday, September 6, 2011 7:42 AM
  • Well, it seems to me that

    1. Declare the following at the CLASS level 
      Dim majorVersionString As String 

    2. Assign it in ThisAdd_Startup:
      majorVersionString= Globals.ThisAddIn.Application.InnerObject.Version.Split(New Char() {"."c})(0)

    3. Pass that to the Ribbon library in the constructor (you'll need to change the constructor):
      Return New SharedLib.UI.SharedRibbonXML(majorVersionString)

    As this is VB the constructor would be a Public Sub in SharedRibbonXML like:
      Private sAppVersion As String

      Public Sub New (appVersion as String)
         'InitializeComponents is usually called in a constructor
         sAppVersion = appVersion
      End Sub

    Now you can use the information in GetCustomUi

    Cindy Meister, VSTO/Word MVP
    Tuesday, September 6, 2011 8:10 AM
  • I just ran this, it is returning always Empty value. On debugging I found that Breakpoint in following Ribbon Method:


    And the breakpoint hit Last on ThisAddin_Startup method. So the majorVersionString value never is able to get initialized on Addin Load :( ...

    Tuesday, September 6, 2011 8:28 AM
  • Hi,


    You can also get the installed office(word,excel,outlook etc..) version by reading registry values.


    Please follow the link with source code will helps you to solve this problem.



    • Edited by psvgopal Tuesday, September 6, 2011 8:39 AM
    • Marked as answer by VChaddha Tuesday, September 6, 2011 10:27 AM
    Tuesday, September 6, 2011 8:37 AM
  • I have checked this too ... but When I look at the Registry Editor in my Windows i could not find this key:

    Software\Microsoft\Windows\CurrentVersion\App Paths


    The last part "App Paths" does not exist, neither in LOCAL_MACHINE nor in CURRENT_USER registry keyset ... Have verified this key in following environments : Office 2010 + Windows 7 and Office 2007 + Windows 7.

    Tuesday, September 6, 2011 9:09 AM
  • Hi,


    For windows 7,

    LocalMachine\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths

    • Marked as answer by VChaddha Tuesday, September 6, 2011 10:27 AM
    Tuesday, September 6, 2011 9:57 AM
  • Ahh ok .. thnx .. Yes I've Windows x64 ... so for x64 :

    LocalMachine\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths

    and for windows 7 x86 the path mentioned earlier should work ... thnx to both of you :-) ... Now I can work it out .. I'll read the paths and then will use FileInfo class to read File version of the application ... 

    Tuesday, September 6, 2011 10:27 AM
  • For 2007 ...

    in Ribbon Xml File use

    <customUI onLoad="Ribbon_Load" xmlns="">


    For 2010 ...

    in Ribbon Xml File use

    <customUI onLoad="Ribbon_Load" xmlns="">
    Wednesday, September 28, 2011 10:11 PM