Installed Excel versions and location

 

Microsoft Excel is probably one of the most used pieces of software on the planet. Spreadsheets are used heavily throughout the business world and Microsoft have enjoyed their Office suite taking a large proportion of businesses

The Microsoft Excel 2007 splash screen

There was a question recently on Stack Overflow which I felt was a challenge to answer as I couldn’t find anywhere online which appeared to give an answer on how to do it. After some time going through the registry, I was able to identify how to figure out which versions of Excel were installed.
The following snippet of code is what I came up with to answer the question, the variable rtn is a Dictionary which stores the version of Excel as the key and the directory in which Excel is installed as the value.

Dim reg As RegistryKey
Dim subKey As RegistryKey
Dim rtn As New Dictionary(Of String, String)

reg = Registry.LocalMachine.OpenSubKey("SOFTWAREMicrosoftOffice")
If reg IsNot Nothing Then
    For Each subKeyName As String In reg.GetSubKeyNames
        subKey = reg.OpenSubKey(subKeyName)
        If subKey IsNot Nothing Then
            If subKey.GetSubKeyNames().Contains("Excel") Then
                subKey = subKey.OpenSubKey("ExcelInstallRoot")
                rtn.Add(subKeyName, subKey.GetValue("Path").ToString)
            End If
        End If
    Next
End If

For Each kvp In rtn
    MessageBox.Show(String.Format("Version: {0} at '{1}Excel.exe'", kvp.Key, kvp.Value))
Next

The code was tested on a Windows XP machine with Microsoft Excel 2003 and 2007 installed on it. In the variable rtn you have a dictionary of the versions (the key) and the directory that Excel is installed in (the value). As you can see in the MessageBox bit at the end of my code, you’ll need to add “Excel.exe” to the end of it as the value only contains the directory.