This is where the information about Excel is stored.
HOW TO CHECK NET VERSION CODE
With the above code segment, we explored the HKEY_CLASSES_ROOT\Excel.Application\CurVer key.
For more info regarding the Registry, have a read through this article I wrote a while back. It’s like an inventory where all of the info about the programs, and the controls are stored. Why? Well, because the registry is the place where all of the settings are saved.
HOW TO CHECK NET VERSION HOW TO
Many people do not know what the registry is, or how to use it.
OK, I said we made use of the registry, let’s pause a bit here. VB.NET Imports Microsoft.Win32 'For registry functions Before we forget, add the Wind32 Namespace: Here, we made use of the registry to obtain our needed info. MessageBox.Show("Excel " + strVersion + " Installed!") //Display Result StrValue = strValue.Substring(strValue.LastIndexOf(".") + 1) //Store Value StrValue = (string)rkVersion.GetValue(string.Empty) //Get Value RkVersion = (strEVersionSubKey, false) //Open Registry Key RegistryKey rkVersion = null //Registry Key To Determine Excel Version String strVersion = null //Determines Excel Version String strValue = null //Value Present In Above Key String strEVersionSubKey = "\\Excel.Application\\CurVer" //HKEY_CLASSES_ROOT/Excel.Application/Curver MessageBox.Show("Excel " & strVersion & " Installed!") 'Display ResultĬ# private void Determine_OfficeVersion_2() StrValue = strValue.Substring(strValue.LastIndexOf(".") + 1) 'Store Value StrValue = rkVersion.GetValue(String.Empty) 'get Value If Not rkVersion Is Nothing Then 'If Key Exists RkVersion = (name:=strEVersionSubKey, writable:=False) 'Open Registry Key Method 2 – The RegistryĪdd the following code: Private Sub Determine_OfficeVersion_2()ĭim strEVersionSubKey As String = "\Excel.Application\CurVer" '/HKEY_CLASSES_ROOT/Excel.Application/Curverĭim strValue As String 'Value Present In Above Keyĭim strVersion As String 'Determines Excel Versionĭim rkVersion As RegistryKey = Nothing 'Registry Key To Determine Excel Version We cannot use switch here, because the data is dynamic / uncertain and not “fixed” such as a Boolean or character data type. The C# equivalent of Select case is switch. Because we do not know what will be returned by CreateInstance, we had to make the Excel object variable dynamic. This basically achieves the same thing as CreateObject.
The nearest equivalent in C# is Activator.CreateInstance. The C# code does not make use of CreateObject, as that is not available in C#. Based on that, we display the appropriate message. Our code instantiates an Excel object, then we determine its version. This allows us to make use of Office from within our code. Add the following Imports / Usings above your class name: Select the COM tab and select your Excel version. Before we can run this, we need to add a Reference to the Excel object library. Remember I spoke about Late Binding? Have a read through this article concerning late binding. MessageBox.Show("Excel Version: " + strEVersion) String strEVersion = null //To identify version MessageBox.Show("Excel Version: " & strEVersion) 'Display ResultĬ# private void Determine_OfficeVersion_1()ĭynamic objEApp = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application")) //Excel object Select Case objEApp.Version 'Determine Version ObjEApp = DirectCast(CreateObject("Excel.Application"), Excel.Application) 'Cast To Excel App VB.NET Private Sub Determine_OfficeVersion_1()ĭim objEApp As Excel.Application 'Excel Objectĭim strEVersion As String 'Identify Version We can use Late Binding, Assembly and even the Registry. There are numerous ways and tools at our disposal. You can however change the Text Properties of the buttons, as follows: Add four buttons to your form, and leave all the default names. DesignĬreate a new project in either VB.NET or C#. This article will show you 4 different ways to determine the Office versions installed. This happens because not enough research of the client’s needs and abilities was done. Many a programmer sees this as an afterthought, sadly. Knowing which version of MS Office is installed on the client computer is vital.