How to check programmatically whether Excel is installed on computer?

  • Thread starter Thread starter Jack
  • Start date Start date
The most trustworthy would be to start it with CreateObject. (or use
GetObject which would get an existing running instance if one was up).
 
Hi Jack,

There are lots of ways, this one attempts to start Excel in the background
and checks for an error to be raised. The drawback is this method of
checking will take longer than other options, the benefit is that it is
simple and will work with any version of Excel.

Public Function IsExcelInstalled() As Boolean
Dim obj As Object

IsExcelInstalled = True

On Error GoTo ErrHandler

Set obj = CreateObject("Excel.Application")
Set obj = Nothing

Exit Function

ErrHandler:
IsExcelInstalled = False
End Function
 
Tom, not running theExcel instance, but the existance of the installed
program I need to check.
 
If you're not satisfied with the CreateObject solution (although I can't see
why... perhaps memory resources, perhaps you need to check remotely?) then
you could inspect the registry for the existence of the
HKEY_CLASSES_ROOT\Excel.Application key.
 
Jack said:
I mean Excel installed, not running.

You didn't say what program you want to use to check it, so there's no
single answer.

In a batch file, you could use the ASSOC command to see if the .XLS file
type has a file association. If it doesn't, either Excel is not
installed or it was not installed correctly. If it does, either Excel
is installed or it has been installed and then uninstalled (I'm not sure
whether the uninstall program deletes the entry). Once you know the
file association, you can use the FTYPE command to get the path to the
executable.

C:\Documents and Settings\Administrator>assoc .xls
.xls=Excel.Sheet.8

C:\Documents and Settings\Administrator>ftype excel.sheet.8
excel.sheet.8="C:\Program Files\Microsoft Office\Office\EXCEL.EXE" /e

This information is also available through the Windows API if you're
using VB (or other language that gives you access to the API).

As someone has already said, if you want to know whether Excel is
actually runnable, you'll have to try to run it.



==
Jack Hamilton
(e-mail address removed)

==
In the end, more than they wanted freedom, they wanted comfort and security.
And in the end, they lost it all - freedom, comfort and security.
Edward Gibbons
 
Tom is exactly right, but since you seem to need more detailed help than Tom
provided....

If Excel is installed, you'll be able to create an instance of the
Excel.Application object. If Excel is not installed, you won't be able to
create an instance of the Excel.Application object. So....attempt to create
an instance of this object and trap for an error (warning: air code).

Dim oXLApp As Object

On Error Resume Next
Set oXLApp = CreateObject("Excel.Application")
If oXLApp Is Nothing Then
MsgBox "Excel is not installed or is not installed correctly"
Else
MsgBox "Excel version " & oXLApp.Version & " is installed in '" &
oXLApp.Path & "'"
End If

There are other ways too. For example, you could use the FindExecutable API
function to determine which program, if any, is associated with the .XLS
extension. This, however, is not foolproof for determining if Excel is
installed because other programs could be associated with the .XLS
extension. You could also check any of a number of different Registry keys.
This also is not reliable because Registry keys are frequently left behind
after a program is uninstalled. Both of these alternatives are also more
work (i.e. require more code) than just trying to instantiate the object.

I think Tom's suggestion of just trying to instantiate the Excel.Application
object is the easiest and most reliable means of determining if Excel (or
any application that is an Automation server) is installed and, moreover,
installed correctly.

Mike
 
Back
Top