5

My VB.NET (3.5) application generates Excel reports.

Newer versions of Excel support the Office Open XML file format, while older versions don't.

I'd like my application to identify which version of Excel is installed on the local machine, and use a different method for generating the report (Newer versions: by generating an XML file. Older versions: by utilizing Excel Automation).

How can I identify the Excel version installed on the local machine?

Cœur
  • 37,241
  • 25
  • 195
  • 267
M.A. Hanin
  • 8,044
  • 33
  • 51

2 Answers2

5

You could open an instance of Excel and check the version:

Dim appExcel As Object
appExcel = CreateObject("Excel.Application")
With appExcel
    Debug.Print(Val(.application.version))
    .quit()
    appExcel = Nothing
End With
Doug Glancy
  • 27,214
  • 6
  • 67
  • 115
3

You can have a look at one of the following registry keys :

HKEY_USERS\.DEFAULT\Software\Microsoft\Office\11.0\Excel 
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel

You should look for the existence of the key, with "Excel" in it, as you can have office 2003 installed, and visio 2007 aside, so both keys will exist, but only one will have an Excel subkey :

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0

Number / Version correspondance

  • Office 9 : Office 2000
  • Office 10 : Office XP (First version to support XML format worksheets)
  • Office 11 : Office 2003
  • Office 12 : Office 2007
  • Office 14 : Office 2010 (fun fact, 13 was skipped)
mathieu
  • 30,974
  • 4
  • 64
  • 90
  • That's a good start! On this machine I have Visio 2003 and Excel 2002. I see HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Excel exists, but HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel doesn't. – M.A. Hanin Apr 10 '11 at 15:40