Román
Román

Reputation: 1953

Detecting Installed Excel Version (and Service Packs)

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!

Upvotes: 5

Views: 8327

Answers (4)

gideon
gideon

Reputation: 19465

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

Upvotes: 2

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104841

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.

Upvotes: 6

McAden
McAden

Reputation: 13970

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)

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564931

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.

Upvotes: 2

Related Questions