Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Raja Ranga
 
Posts: n/a
Default 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   Report Post  
Jan Karel Pieterse
 
Posts: n/a
Default

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   Report Post  
Raja Ranga
 
Posts: n/a
Default

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   Report Post  
NickHK
 
Posts: n/a
Default

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   Report Post  
Jan Karel Pieterse
 
Posts: n/a
Default

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   Report Post  
Paul Clement
 
Posts: n/a
Default

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   Report Post  
Harald Staff
 
Posts: n/a
Default

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
Formula in Visual Basic For Excel imej-clavier Excel Discussion (Misc queries) 2 December 23rd 04 01:43 PM
How do I open each workbook in it's own version of Excel? RKOCT Excel Discussion (Misc queries) 3 December 8th 04 11:32 PM
I cant use englisch function names in a swedich version of excel PE Excel Discussion (Misc queries) 2 December 7th 04 01:00 AM
Excel 2003 Database Driver Visual FoxPro 7 on Server 2003. Cindy Winegarden Excel Discussion (Misc queries) 0 November 28th 04 12:07 AM


All times are GMT +1. The time now is 04:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"