How to check Excel version number with .net?

  • Thread starter Thread starter Alain \Mbuna\
  • Start date Start date
A

Alain \Mbuna\

Hi everybody.

Does anyone know what code I should use to check for the version number of
Excel, installed on a computer?

Thanks.

Alain.
 
Alain "Mbuna" said:
Does anyone know what code I should use to check for the version number of
Excel, installed on a computer?

\\\
Dim o As Object = CreateObject("Excel.Application")
If Not o Is Nothing Then
On Error Resume Next
MsgBox( _
"Installed version of Excel: " & _
DirectCast(o.Version, String) _
)
o.Quit()
On Error GoTo -1
Marshal.ReleaseComObject(o)
Else
MsgBox("Maybe Excel is not installed!")
End If
///
 
That was fast!!!

Thanks a lot.

Alain.


Herfried K. Wagner said:
\\\
Dim o As Object = CreateObject("Excel.Application")
If Not o Is Nothing Then
On Error Resume Next
MsgBox( _
"Installed version of Excel: " & _
DirectCast(o.Version, String) _
)
o.Quit()
On Error GoTo -1
Marshal.ReleaseComObject(o)
Else
MsgBox("Maybe Excel is not installed!")
End If
///
 
What is the Marshal thing???

This word is underlined in the code, saying it is not declared???

Alain.
 
Herfried said:
\\\
Dim o As Object = CreateObject("Excel.Application")
If Not o Is Nothing Then
On Error Resume Next
MsgBox( _
"Installed version of Excel: " & _
DirectCast(o.Version, String) _
)
o.Quit()
On Error GoTo -1
Marshal.ReleaseComObject(o)
Else
MsgBox("Maybe Excel is not installed!")
End If
///

If you looked in help you would see it.

Try:
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
 
Alain "Mbuna" said:
What is the Marshal thing???

This word is underlined in the code, saying it is not declared???

Import the namespace 'System.Runtime.InteropServices'. It's used to release
the Excel COM object to free Excel.
 
¤ Hi everybody.
¤
¤ Does anyone know what code I should use to check for the version number of
¤ Excel, installed on a computer?
¤

You can also use the FindExecutable API function call (which doesn't launch the Excel application):

Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As
String, _
ByVal lpDirectory As
String, _
ByVal lpResult As
System.Text.StringBuilder) As Int32

Function IsExcelInstalled(ByRef FileVersionMajor As String) As Boolean

Dim DummyFile As String
Dim FileDir As String

Dim FilePath As New System.Text.StringBuilder(255)
DummyFile = "e:\My Documents\book1.xls"

If FindExecutable(DummyFile, FileDir, FilePath) > 32 Then
IsExcelInstalled = True
FileVersionMajor =
System.Diagnostics.FileVersionInfo.GetVersionInfo(FilePath.ToString).FileMajorPart
End If

End Function


Paul
~~~~
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top