Detect what version (if any) of Excel is installed

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking for a way (maybe something in the registry?) to determine what version, if any, of Excel is installed on a PC. I would like it to work regardless of whether Excel was installed as a standalone app or with any of the various Office editions

Thanks very much.
 
Hi Keith,

Use

application.version

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Keith Brautigam said:
I am looking for a way (maybe something in the registry?) to determine
what version, if any, of Excel is installed on a PC. I would like it to
work regardless of whether Excel was installed as a standalone app or with
any of the various Office editions.
 
Thanks Bob

Actually I should have been clearer -- and maybe this is the wrong newsgroup for my question. The situation is that I have a C++/MFC app and I want to detect the Excel version from it

Thanks.
 
Use

application.version
...

Kinda Chicken & Egg-ish. If there's no version of Excel at all, there's no way
to execute this statement. Check whether Excel exists at all could be done by
searching for EXCEL.EXE.
 
Hi Keith,

You can try to create a new object based on the class "Excel.Application".
That should return the latest version of Excel installed on the user's
machine. Next, check the Version property of the Application object to see
what version it is. If the user doesn't have Excel installed, you'll get a
runtime error (maybe 429) when you try to instantiate the object. In VB, it
would look something like this:

Public Function gsGetXLVersion() As String
Dim xlApp As Object

On Error GoTo ErrHandler

Set xlApp = CreateObject("Excel.Application")

gsGetXLVersion = xlApp.Version

ExitRoutine:
If Not xlApp Is Nothing Then
xlApp.Quit
Set xlApp = Nothing
End If
Exit Function
ErrHandler:
Resume ExitRoutine
End Function


The function will return an empty string if Excel is not installed. If it
is, it will return a string representing the version number. You can take
anything before the decimal separator to get the version number. XL95
returns "7.x", 97 returns "8x", 2000 returns "9.x", 2002 returns "10.x", and
2003 returns "11.x".

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
or trying to create an instance. I guess that would fail if Excel wasn't
present.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Check whether Excel exists at all could be done by
searching for EXCEL.EXE.

Rather than a slow file search for Excel.exe, it would be much
faster to use FindExecutable to find the program that is
associated with the 'xls' file extension.


Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Declare Function FindExecutable Lib "shell32.dll" _
Alias "FindExecutableA" ( _
ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long


Sub AAA()

Dim FName As String
Dim FNum As String
Dim ExeName As String
Dim Res As Long
FName = String$(255, " ")
ExeName = String$(255, " ")
Res = GetTempFileName(CurDir, "", 0&, FName)
FName = Application.Trim(FName)
Mid$(FName, Len(FName) - 2, 3) = "xls"
FNum = FreeFile
Open FName For Output As #FNum
Close #FNum
Res = FindExecutable(FName, vbNullString, ExeName)
Kill FName
If Res > 32 Then
' association found
ExeName = Left$(ExeName, InStr(ExeName, Chr(0)) - 1)
Else
' no association found
ExeName = ""
End If
MsgBox "Excel is: " & ExeName

End Sub

This won't tell you what version of Excel is found (that would
call for a variety of registry calls) but would indicate that
some version of Excel is installed.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top