Excel version identification from Visual Basic

R

Raja Ranga

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?

Regards,
Raja Ranga.
 
J

Jan Karel Pieterse

Hi Raja,
Could you please specify how can this be done? Any APIs or other libraries
to be used?

If you have set a ref to Excel. you could do:

Sub test()
Dim oXLApp As New Excel.Application
Set oXLApp = New Excel.Application
MsgBox oXLApp.Version
oXLApp.Quit
Set oXLApp = Nothing
End Sub

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com
 
R

Raja Ranga

Hi Jan Karel,

Thanks for your reply. I would like to give you more clarity on my
requirement.

I have an application where I am referring Excel 2003 from Visual Basic
references and creating an Excel.Application object and generating a report.
But the same functionality fails when the application is run on a machine
with Excel 97 installed in it.

The Excel object creation itself fails as path mentioned in references does
not exist in the user's machine.

Please clarify how do I get the version of Excel without creating/using
Excel object.

Regards,
Raja Ranga.
 
N

NickHK

Raja,
Private Sub Form_Load()
Dim XLApp As Object

Set XLApp = CreateObject("Excel.Application")

'Decide what to do depending on the version
Select Case XLApp.Version
Case "10.0"
Case "9.0"
Case Else
End Select

XLApp.quit
Set XLApp = Nothing
End Sub

NickHK
 
J

Jan Karel Pieterse

Hi Raja,
Please clarify how do I get the version of Excel without creating/using
Excel object.

I guess you could check in the registry whether a certain path exists?

If you have Excel 2003 installed, a path like :

HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel

should exist.

For other versions this is:

97: HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Excel
2000: HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Excel
XP: HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Excel

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com
 
P

Paul Clement

¤ 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)
 
Top