VBA Tip: Perform an Action Depending on Excel's Version
Not all Excel features available in the latest version of Excel may be compatible with older versions.
In some cases, it may be useful to perform a different action based on the version of Excel used by the user, using Val(Application.Version)
, which returns the version number of Excel.
Excel Versions
Here are the version numbers of Excel to use for testing:
8 | Excel 97 (Mac: 98) |
9 | Excel 2000 (Mac: 2001) |
10 | Excel 2002 |
11 | Excel 2003 (Mac: 2004) |
12 | Excel 2007 (Mac: 2008) |
14 | Excel 2010 (Mac: 2011) |
15 | Excel 2013 (Mac: 2016) |
16 | Excel 2016, 2019, 365 |
Example Usage
Often, when it is necessary to perform a different action based on the version of Excel used by the user, the action needs to be different for Excel versions prior to 2007.
Here is the code you can use to achieve that:
If Val(Application.Version) < 12 Then
'If Excel version is prior to 2007
Else
'If Excel version is 2007 or later
End If
If you want to avoid situations where this code works perfectly for you but fails for another user who has the same version of Excel, remember to use the Val function as shown in this example!