Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel version (if installed)

Status
Not open for further replies.

ADoozer

Programmer
Dec 15, 2002
3,487
0
0
AU
im looking for the easiest way to determine if and which version of excel is installed on a pc.

i know where to look in the registry for the info(HKEY_CLASSES_ROOT\Excel.Application\CurVer), but im sure there is a much easier/simpler way.

anyone know it?!?

any input appreciated!! If somethings hard to do, its not worth doing - Homer Simpson
 
nope... still using the registry route... i know i can get the version IF excel is installed using myExcel.version but this doesnt help if excel isnt installed on the machine (other than catching the error)

still looking for simple solution though! If somethings hard to do, its not worth doing - Homer Simpson
 
one last push...

anyone got any ideas???

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Here's a way, but it may be easier to just read the registry

Option Explicit
Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal Length As Long)
Private Declare Function FindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As _
String, ByVal lpResult As String) As Long
Private Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersionl As Integer
dwStrucVersionh As Integer
dwFileVersionMSl As Integer
dwFileVersionMSh As Integer
dwFileVersionLSl As Integer
dwFileVersionLSh As Integer
dwProductVersionMSl As Integer
dwProductVersionMSh As Integer
dwProductVersionLSl As Integer
dwProductVersionLSh As Integer
dwFileFlagsMask As Long
dwFileFlags As Long
dwFileOS As Long
dwFileType As Long
dwFileSubtype As Long
dwFileDateMS As Long
dwFileDateLS As Long
End Type
Public Function CheckFileVersion() As Variant
On Error GoTo HandelCheckFileVersionError
Dim FileName, Dummy As String
Dim FileToExec As String * 255
Dim retVal As Long
FileToExec = Space(255)
'You need a dummy excel file to open Possibly create one then destroy
FileName = App.Path & "\Book1.xls"
retVal = FindExecutable(FileName, Dummy, FileToExec)
FileToExec = Trim(FileToExec)
Dim lDummy As Long, lsize As Long, rc As Long
Dim lVerbufferLen As Long, lVerPointer As Long
Dim sBuffer() As Byte
Dim udtVerBuffer As VS_FIXEDFILEINFO
Dim ProdVer As String
lsize = GetFileVersionInfoSize(FileToExec, lDummy)
If lsize < 1 Then Exit Function
ReDim sBuffer(lsize)
rc = GetFileVersionInfo(FileToExec, 0&, lsize, sBuffer(0))
rc = VerQueryValue(sBuffer(0), &quot;\&quot;, lVerPointer, lVerbufferLen)
MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & &quot;.&quot; & Format$(udtVerBuffer.dwProductVersionMSl)
CheckFileVersion = ProdVer
Exit Function
HandelCheckFileVersionError:
CheckFileVersion = &quot;N/A&quot;
Exit Function
End Function

Private Sub Command1_Click()
MsgBox CheckFileVersion()
End Sub
 
eeek! thats just as meaty as the registry route...

hmmm... so createobject and catch the error it is then LOL

anyone know the error number for excel not being installed (i would check but all my machines have office installed)

thanks DrJJ!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Actually you could add this:
If retVal <= 32 Then
CheckFileVersion &quot;Excel Not Installed&quot;
Exit Function
End If
after this:
retVal = FindExecutable(FileName, Dummy, FileToExec)
 
Actually you could add this:
If retVal <= 32 Then
CheckFileVersion = &quot;Excel Not Installed&quot;
Exit Function
End If
after this:
retVal = FindExecutable(FileName, Dummy, FileToExec)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top