Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I tell if Excel is Installed?

Status
Not open for further replies.

MrsPie

Programmer
Jul 23, 2003
20
US
I want to allow the ability to export a recordset to Excel - but some of my users may not have Excel installed.

Is there something that can check for the existence of Excel on a machine before I attempt to open it? I'm using great code found on an earlier thread, but my concern is that it will generate an error if there is no Excel.

. . .
Dim objExcelApp As Excel.Application
Dim xlsExcelSheet As Excel.Worksheet
Dim col As Long
Dim row As Long

Set objExcelApp = New Excel.Application
objExcelApp.Visible = False
objExcelApp.Workbooks.Add

If Val(objExcelApp.Application.Version) >= 8 Then
Set xlsExcelSheet = objExcelApp.Worksheets(1)
Else
Set xlsExcelSheet = objExcelApp
End If
. . .

Also, will referencing the Excel 9.0 Object Library cause a break if Excel isn't installed?

Thanks much!
 
Error trapping is the way to go.
For a little more information, you could try looking in the registry.
HKEY_LOCAL_MACHINE
SOFTWARE
MICROSOFT
WINDOWS
CURRENT VERSION
APP PATHS
EXCEL.EXE

to get the path, then maybe check the file still exists?
 
I understand error trapping, but normally I trap for a specific error. Without a specific error number I'm trapping blindly (on ANY error, skip the export to Excel).

How, in code, do I look in the registry?

Thank you!
 
you could uninstall your version of excel, then put a message box too see what error # you get, then you would know which error it would be
 
Try somthing along these lines:
Code:
Dim bExcelInstalled As Boolean
Dim myXL As Object

    On Error Resume Next
    Set myXL = CreateObject("Excel.Application")
    On Error Goto ErrorHandler
    If (myXL Is Nothing) Then
        bExcelInstalled = False
    Else
        bExcelInstalled = True
    End If

Regards
-- Gavin
 
I'm taking the easy way out. My kids are about to get a new computer - I'll test this code on their machine. Thanks for the ideas, I'll let you know what works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top