Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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. |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
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 |
#6
|
|||
|
|||
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) |
#7
|
|||
|
|||
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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? | Excel Discussion (Misc queries) | |||
Formula in Visual Basic For Excel | Excel Discussion (Misc queries) | |||
How do I open each workbook in it's own version of Excel? | Excel Discussion (Misc queries) | |||
I cant use englisch function names in a swedich version of excel | Excel Discussion (Misc queries) | |||
Excel 2003 Database Driver Visual FoxPro 7 on Server 2003. | Excel Discussion (Misc queries) |