views:

402

answers:

4

Hi all

I need to be able to detect which version of Excel I have installed in my machine from some .NET code I'm developing. I'm currently using Application.Version for that, but it doesn't give me information about Service Packs.

I would preferably to steer away from something like this: http://www.mvps.org/access/api/api0065.htm

Managed code welcomed!

+2  A: 

Unfortunately, that approach is the only reliable approach. Even Microsoft suggests using a similar technique (this is for checking manually, but the concept is identical).

If you want to do this in managed code, I'd suggest just porting the code from your link, and making a class that's easily extensible when new service packs are released.

Reed Copsey
A: 

While not robust, that approach is the only way I know of.

Keep in mind you don't have to check for an exact match. You can use comparisons on the individual values to see if the version you have is for example, SP1 or newer. you know it's newer if the version number is greater than or equal to "11.0.6355.0" (you'll need to implement the comparison)

McAden
+3  A: 
Public Shared Function GetExcelVersion() As Integer
    Dim excel As Object = Nothing
    Dim ver As Integer = 0
    Dim build As Integer
    Try
        excel = CreateObject("Excel.Application")
        ver = excel.Version
        build = excel.Build
    Catch ex As Exception
        'Continue to finally sttmt
    Finally
        Try
            Marshal.ReleaseComObject(excel)
        Catch
        End Try
        GC.Collect()
    End Try
    Return ver
End Function

Returns 0 if excel not found.

Shimmy
A: 

You could check the app paths in the registry for the path to the exe and then get its version: See http://www.codeproject.com/KB/office/getting_office_version.aspx

giddy