ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel version identification from Visual Basic (https://www.excelbanter.com/excel-discussion-misc-queries/3972-excel-version-identification-visual-basic.html)

Raja Ranga

Excel version identification from Visual Basic
 
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.





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


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.

"Jan Karel Pieterse" wrote in message
...
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




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

"Raja Ranga" wrote in message
...
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.

"Jan Karel Pieterse" wrote in message
...
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






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\E xcel

should exist.

For other versions this is:

97: HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Ex cel
2000: HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Ex cel
XP: HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\E xcel

Regards,

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


Paul Clement

On Mon, 17 Jan 2005 12:47:44 +0530, "Raja Ranga"
wrote:

¤ 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 ~~~
Microsoft MVP (Visual Basic)

Harald Staff

Hi Raja

If you set references to Excel 11 object library, then it will err if Excel
11 is not there. So code to check versions won't run and it's too late. See
http://www.erlandsendata.no/english/...baoleolebasics

If you develop for multiple versions, use the oldest version yourself. No
way around that.

HTH. Best wishes Harald


"Raja Ranga" skrev i melding
...

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.





All times are GMT +1. The time now is 09:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com