I would like to determine the version of Office/Excel in a VSTO Addin when CreateRibbonExtensibilityObject()
is called on the Addin. I have encountered an issue with this, and have encountered:
- the
this.Application
of the addin isnull
, it is not yet set by VSTO at this time. - the
ThisAddIn_Startup(..)
is called after theCreateRibbonExtensibilityObject()
.
this.Application.Version
is not available yet as the Addin seems not yet initialized at this time. Is there a way to determine the version of Excel (12, 14, or 15) at the time when the VSTO runtime calls CreateRibbonExtensibilityObject()
on the Addin?
UPDATE
Finding that the ItemProvider was instantiated, I used the following to get the major office version.
FieldInfo temp = this.ItemProvider.GetType().GetField("_officeVersion", BindingFlags.NonPublic | BindingFlags.Instance);
uint officeVersion = (uint)temp.GetValue(this.ItemProvider);
I am accepting SliverNinja's answer too.