View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Detect what version (if any) of Excel is installed


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



"Harlan Grove" wrote in message
...
"Bob Phillips" wrote...
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.

--
To top-post is human, to bottom-post and snip is sublime.