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:
this.Application
of the addin is null
, it is not yet set by VSTO at this time. ThisAddIn_Startup(..)
is called after the CreateRibbonExtensibilityObject()
.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.
On the File menu, point to New, and then click Project. In the templates pane, expand Visual C# or Visual Basic, and then expand Office/SharePoint. Under the expanded Office/SharePoint node, select the Office Add-ins node. In the list of project templates, choose an Outlook VSTO Add-in project.
Deployment type If you want to register a VSTO Add-in to all users on a computer, you must use Windows Installer to deploy the VSTO Add-in. For more information about these deployment types, see Deploy an Office solution by using ClickOnce and Deploy an Office solution by using Windows Installer.
You can use System.Diagnostics
to access the currently running Office process (excel.exe
), grab the path to the process filename (MainModule
), then use FileInfoVersion
to determine the major product version.
int majorVersion = FileVersionInfo.GetVersionInfo(Process.GetCurrentProcess().MainModule.FileName).ProductMajorPart;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With