OL: How to Programmatically Determine the Version of Outlook (238404)



The information in this article applies to:

  • Microsoft Outlook 2002
  • Microsoft Outlook 2000
  • Microsoft Outlook 98
  • Microsoft Outlook 97

This article was previously published under Q238404

SUMMARY

There may be times when your Outlook solution needs to determine which version of Outlook is currently running so that your code can take appropriate action. This article describes an approach you can use to accomplish this.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: The Outlook 97 and Outlook 98 object models do not provide a direct way to determine the installed version of Outlook, but you can obtain the version of Outlook from the OutlookVersion property of an item. The OutlookVersion property contains the version of Outlook that created the item, and it is in the format of "nn.nn" (without quotation marks). The "nn.nn" format is the major and minor Outlook version numbers. If you programmatically create a temporary item, you can retrieve the version of Outlook that created the item. This version is the current version of Outlook that is installed. The advantage of using this approach is that it works with all versions of Outlook, but the disadvantage is that you cannot retrieve the actual build number.

Starting with Outlook 2000, the Application object has a Version property that returns the full version number of Outlook, including the build number, in a format of "nn.nn.nnnn.nnnn" (without quotation marks). If your solution must work with Outlook 2000 and later, this Version property is probably the best approach to use. The example in this article describers how to use an item's OutlookVersion property because this approach works in all versions of Outlook, and it is more difficult to implement.

To Use the OutlookVersion Property

The approach below creates a temporary Outlook item and obtains the version number using the OutlookVersion property. Then the temporary item is deleted. One advantage of using this approach is that it will work in situations where any version of Outlook may be installed on the system.
Function CheckOLVersion()

   Dim dblVersion
   Dim objTestItem

   ' Create a temporary mail message
   Set objTestItem = Application.CreateItem(0)

   ' Save the message so the OutlookVersion property is set.
   objTestItem.Save

   ' Obtain the version of Outlook
   dblVersion = CDbl(objTestItem.OutlookVersion)

   ' Set the function value accordingly.
   ' (You can't use comparison operators with Select Case in VBScript)
   If dblVersion < 8.5 Then
      CheckOLVersion = "97"
   ElseIf dblVersion < 9 Then
      CheckOLVersion = "98"
   ElseIf dblVersion < 10 Then
      CheckOLVersion = "2000"
   Else
      CheckOLVersion = "2002"
   End If

   ' Delete the temporary mail message
   objTestItem.Delete

   Set objTestItem = Nothing

End Function
				
You would typically call this Visual Basic function from your code in the following manner:

Select Case CheckOLVersion
   Case "97"
      ' Insert "Outlook 97" code here
   Case "98"
      ' Insert "Outlook 98" code here
   Case "2000"
      ' Insert "Outlook 2000" code here
   Case "2002"
      ' Insert "Outlook 2002" code here
End Select
				
IMPORTANT: This solution is only designed to work with the four versions of Outlook specified in the previous sample code. Future releases of Outlook will require modification to the code in order to distinguish that version from Outlook 2002.

REFERENCES

For additional information about available resources and answers to commonly asked questions about Microsoft Outlook solutions, click the following article numbers to view the articles in the Microsoft Knowledge Base:

287530 OL2002: Questions About Custom Forms and Outlook Solutions

146636 OL2000: Questions About Custom Forms and Outlook Solutions

182349 OL98: Questions About Custom Forms and Outlook Solutions

170783 OL97: Questions About Customizing or Programming Outlook


Modification Type:MajorLast Reviewed:9/12/2003
Keywords:kbhowto kbProgramming KB238404