RobDog888
Oct 25th, 2005, 09:48 PM
When writting programs that need to support multiple versions of an Office app you need a way to evaluate the installed app. There are only two methods to obtain the version/build information for all Office apps. Once you have the version info you can branch out and perform vertain functions that are only supported in that version or set a flag variable to use throughout your app to handle executing certain lines of code or not.
1.) The code in Command1_Click procedure is only for Outlook and InfoPath applications. In these two apps the .Version information contains the Major, Minor, Revision and Build (14.0.0.6359).
2.) The code in command2_Click procedure covers the rest of the Office applications. The .Version information only contains the Major and Minor numbers (14.0).
Visual Basic 6.0 Early Binding Code Example:
Option Explicit
'Add a reference to your desired office app
'MS [inset app name here] xx.0 Object Library
Private Sub Command1_Click()
'Format for Outlook and InfoPath (Outlook shown)
'Requires trimming of the build info
Dim oApp As Outlook.Application
Dim sBuild As String
Dim sVersion As String
Set oApp = New Outlook.Application
'Get major build only to make it easier to determine version
sBuild = Left$(oApp.Version, InStr(1, oApp.Version, ".") + 1)
Select Case sBuild
Case "7.0"
sVersion = "97" 'Outlook
Case "8.0"
sVersion = "98" 'Outlook
Case "9.0"
sVersion = "2000" 'Outlook
Case "10.0"
sVersion = "2002" 'Outlook
Case "11.0"
sVersion = "2003" 'Outlook & InfoPath
Case "12.0"
sVersion = "2007" 'Outlook & InfoPath
Case "14.0"
sVersion = "2010" 'Outlook
Case Else
sVersion = "Too Old!"
End Select
MsgBox "Outlook Build: " & oApp.Version & vbNewLine & "Outlook Version: " & sVersion, _
vbOKOnly + vbInformation, "Office Version"
oApp.Quit
Set oApp = Nothing
End Sub
Private Sub Command2_Click()
'Format for most other Office Apps
'MS Access used for this example
Dim oApp As Access.Application
Dim sVersion As String
Set oApp = New Access.Application
Select Case oApp.Version
Case "7.0"
sVersion = "95"
Case "8.0"
sVersion = "97"
Case "9.0"
sVersion = "2000"
Case "10.0"
sVersion = "2002"
Case "11.0"
sVersion = "2003"
Case "12.0"
sVersion = "2007"
Case "14.0"
sVersion = "2010"
Case Else
sVersion = "Too Old!"
End Select
MsgBox "Outlook Build: " & oApp.Version & vbNewLine & "Outlook Version: " & sVersion, _
vbOKOnly + vbInformation, "Office Version"
oApp.Quit
Set oApp = Nothing
End Sub
Visual Basic 6.0 Late Binding Code Example:
Option Explicit
'Excel example being used
Private Sub Form_Load()
On Error GoTo MyError
Dim oApp As Object
Dim sVersion As String
Set oApp = GetObject(, "Excel.Application")
If TypeName(oApp) = "Nothing" Then
Set oApp = CreateObject("Excel.Application")
End If
Select Case Left$(oApp.Version, InStr(1, oApp.Version, ".") + 1)
Case "8.0"
sVersion = "97"
Case "9.0"
sVersion = "2000"
Case "10.0"
sVersion = "2002"
Case "11.0"
sVersion = "2003"
Case "12.0"
sVersion = "2007"
Case "14.0"
sVersion = "2010"
Case else
sVersion = "Too Old!"
End Select
MsgBox "Excel version: " & sVersion
Exit Sub
MyError:
If Err.Number = 429 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
End If
End Sub
1.) The code in Command1_Click procedure is only for Outlook and InfoPath applications. In these two apps the .Version information contains the Major, Minor, Revision and Build (14.0.0.6359).
2.) The code in command2_Click procedure covers the rest of the Office applications. The .Version information only contains the Major and Minor numbers (14.0).
Visual Basic 6.0 Early Binding Code Example:
Option Explicit
'Add a reference to your desired office app
'MS [inset app name here] xx.0 Object Library
Private Sub Command1_Click()
'Format for Outlook and InfoPath (Outlook shown)
'Requires trimming of the build info
Dim oApp As Outlook.Application
Dim sBuild As String
Dim sVersion As String
Set oApp = New Outlook.Application
'Get major build only to make it easier to determine version
sBuild = Left$(oApp.Version, InStr(1, oApp.Version, ".") + 1)
Select Case sBuild
Case "7.0"
sVersion = "97" 'Outlook
Case "8.0"
sVersion = "98" 'Outlook
Case "9.0"
sVersion = "2000" 'Outlook
Case "10.0"
sVersion = "2002" 'Outlook
Case "11.0"
sVersion = "2003" 'Outlook & InfoPath
Case "12.0"
sVersion = "2007" 'Outlook & InfoPath
Case "14.0"
sVersion = "2010" 'Outlook
Case Else
sVersion = "Too Old!"
End Select
MsgBox "Outlook Build: " & oApp.Version & vbNewLine & "Outlook Version: " & sVersion, _
vbOKOnly + vbInformation, "Office Version"
oApp.Quit
Set oApp = Nothing
End Sub
Private Sub Command2_Click()
'Format for most other Office Apps
'MS Access used for this example
Dim oApp As Access.Application
Dim sVersion As String
Set oApp = New Access.Application
Select Case oApp.Version
Case "7.0"
sVersion = "95"
Case "8.0"
sVersion = "97"
Case "9.0"
sVersion = "2000"
Case "10.0"
sVersion = "2002"
Case "11.0"
sVersion = "2003"
Case "12.0"
sVersion = "2007"
Case "14.0"
sVersion = "2010"
Case Else
sVersion = "Too Old!"
End Select
MsgBox "Outlook Build: " & oApp.Version & vbNewLine & "Outlook Version: " & sVersion, _
vbOKOnly + vbInformation, "Office Version"
oApp.Quit
Set oApp = Nothing
End Sub
Visual Basic 6.0 Late Binding Code Example:
Option Explicit
'Excel example being used
Private Sub Form_Load()
On Error GoTo MyError
Dim oApp As Object
Dim sVersion As String
Set oApp = GetObject(, "Excel.Application")
If TypeName(oApp) = "Nothing" Then
Set oApp = CreateObject("Excel.Application")
End If
Select Case Left$(oApp.Version, InStr(1, oApp.Version, ".") + 1)
Case "8.0"
sVersion = "97"
Case "9.0"
sVersion = "2000"
Case "10.0"
sVersion = "2002"
Case "11.0"
sVersion = "2003"
Case "12.0"
sVersion = "2007"
Case "14.0"
sVersion = "2010"
Case else
sVersion = "Too Old!"
End Select
MsgBox "Excel version: " & sVersion
Exit Sub
MyError:
If Err.Number = 429 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
End If
End Sub