How can I tell if Excel is installed using Access 97 VBA?

J_Orrell

Registered User.
Local time
Today, 18:34
Joined
May 17, 2004
Messages
55
Hi folks, me again.

I'm building a form for the client which will allow the results of a query to be exported to Excel using a button on the form. No problem exporting: sussed how to do that. What I want to know now is how can I tell using Access 97 VBA if the client has Excel installed on their PC? I want to disable the option if the client hasn't got Excel installed. The only thing I can think of so far is to try to open an instance of Excel and check for an error-message; not a very good solution at all.

Thanks again
 
There may be ways to breaks this but Excel is normally install in the same directory as Access so this should do the trick: -

Code:
Option Explicit
Option Compare Text


Sub Test()

    MsgBox IsInstalled("EXCEL.EXE")
    MsgBox IsInstalled("WINWORD.EXE")
    MsgBox IsInstalled("POWERPNT.EXE")

End Sub


Public Function IsInstalled(ByVal strProgramName As String) As Boolean

    IsInstalled = Dir(SysCmd(acSysCmdAccessDir) & strProgramName) = strProgramName

End Function
Would be called with something like this: -

Me.cmdMyCommandButton.Enabled = IsInstalled("EXCEL.EXE")

#If False Then ' Compiler directive to tell it to stop laughing at me while I type this stuff.

Explaination of code: -

Me.cmdMyCommandButton.Enabled = IsInstalled("EXCEL.EXE")
The Enabled property is set to the return value of the public function IsInstalled("EXCEL.EXE")

Public Function IsInstalled(ByVal strProgramName As String) As Boolean
This function receives "EXCEL.EXE" as strProgramName by value.

SysCmd(acSysCmdAccessDir) which is an Access function returns the Access directory.
(Typically "C:\Program Files\Microsoft Office\Office\") or whatever.

SysCmd(acSysCmdAccessDir) & strProgramName would therefore be: -
"C:\Program Files\Microsoft Office\Office\EXCEL.EXE"

Dir (SysCmd(acSysCmdAccessDir) & strProgramName)
returns "EXCEL.EXE" if found or a ZLS if not found.

Dir(SysCmd(acSysCmdAccessDir) & strProgramName) = strProgramName
equates to True XOR False.

IsInstalled = Dir(SysCmd(acSysCmdAccessDir) & strProgramName) = strProgramName
returns True XOR False to the caller.

#End If ' Compiler may start laughing again.

Hope that helps.

Regards,
Chris.
 
Last edited:
Cheers, never though of that. Sorry for the delay in offering thanks: been away on business. Will try what you say.

John
 

Users who are viewing this thread

Back
Top Bottom