¤ Hello,
¤
¤ I would like to identify the version of MS Excel i.e., whether it is a MS
¤ Excel 97 or Excel 2003 from a Visual Basic program.
¤
¤ Could you please specify how can this be done? Any APIs or other libraries
¤ to be used?
¤
You can use the FindExecutable API function call along with the FileSystemObject
(Microsoft Scripting Runtime library). If your app will be running on Windows 95
you can use the GetFileVersionInfo API (instead of the FSO) which requires quite
a bit more code.
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal
lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Function ExcelVersion() As String
Dim strDummyFile As String
Dim strDir As String
Dim strFilePath As String * 255
Dim strExcelPath As String
strDummyFile = "C:\My Documents\Dummy.xls"
If FindExecutable(strDummyFile, strDir, strFilePath) > 32 Then
strExcelPath = TrimNull(strFilePath)
Dim objFSO As New Scripting.FileSystemObject
ExcelVersion = objFSO.GetFileVersion(strExcelPath)
End If
End Function
Function TrimNull(item As String) As String
Dim pos As Integer
pos = InStr(item, Chr$(0))
If pos Then
TrimNull = Left$(item, pos - 1)
Else: TrimNull = item
End If
End Function
GetFileVersionInfo API example:
http://vbnet.mvps.org/code/fileapi/filesearchinfo.htm
Paul ~~~
[email protected]
Microsoft MVP (Visual Basic)