Tuesday, January 31, 2017

VBA code to return version of excel application !!!

Excel version is one of the important factor while developing macros which executes on various systems. It is quite possible to have different office version on installed on different systems. It may through runtime errors in macro code when executed to a different excel version.  Thus, to prevent such kind of bugs we can determine excel version to add version specific error handler in VBA code. Using VBA code we can identify version of currently install excel application.




Here is a code to determine version of currently install excel application:

Sub Retrieve_Excel_Version()
' Author: Dreams24
' Written for VBA Tricks and tips blog
' https://www.vbatricksntips.com

'Declare variables
Dim exl_ver As Double

' Assign value to variable
exl_ver = Application.Version

' Select case statements
Select Case exl_ver
    Case "7.0" Or "7"
        MsgBox "You are using Microsoft Excel 95.", vbInformation, "Excel Version"
    Case "8.0" Or "8"
        MsgBox "You are using Microsoft Excel 97.", vbInformation, "Excel Version"
    Case "9.0" Or "9"
        MsgBox "You are using Microsoft Excel 2000.", vbInformation, "Excel Version"
    Case "10.0" Or "10"
        MsgBox "You are using Microsoft Excel 2002.", vbInformation, "Excel Version"
    Case "11.0" Or "11"
        MsgBox "You are using Microsoft Excel 2003.", vbInformation, "Excel Version"
    Case "12.0" Or "12"
        MsgBox "You are using Microsoft Excel 2007.", vbInformation, "Excel Version"
    Case "14.0" Or "14"
        MsgBox "You are using Microsoft Excel 2010.", vbInformation, "Excel Version"
    Case "15.0" Or "15"
        MsgBox "You are using Microsoft Excel 2013.", vbInformation, "Excel Version"
    Case Else
        MsgBox "You are using Microsoft Excel 2016.", vbInformation, "Excel Version"
End Select

End Sub

No comments: