{"id":4638,"date":"2024-02-02T16:58:34","date_gmt":"2024-02-02T16:58:34","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/wp\/?p=4638"},"modified":"2024-02-02T16:58:34","modified_gmt":"2024-02-02T16:58:34","slug":"how-to-get-excel-version-using-vba-code","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2024\/02\/how-to-get-excel-version-using-vba-code\/","title":{"rendered":"How to Get Excel version using VBA Code"},"content":{"rendered":"
Dear Friends,<\/p>\n
Usually while working on any of the VBA projects, it becomes important for me to first check the version of excel which user is using and based on that certain functionality of my tool may or may not work. For Example: If you have some sales data using more than 256 columns then if user is using Excel 2003, then it would not be possible as Excel 2003 has got only 256 columns. But if user is using any higher version like Excel 2007 etc. then it is possible to do so without any error as they have got 16000+ columns in it. This way before processing the data if you can identify the version of the excel user is using then you will be able to handle the error without crashing the excel.<\/p>\n
As user I would always prefer a clear message stating that “this functionality is not available in so and so Excel version” rather than getting some weird Microsoft error message and messing up other functionalities as well.<\/p>\n
It is a very simple piece of code which will determine which version of excel user is using. Whenever you call the bellow function at any moment of time when it is necessary to check the version of the excel.<\/p>\n
\nFunction GetVersion() As String\n Dim verNo As Integer\n verNo = VBA.Val(Application.Version)\n Select Case verNo\n Case 8:\n GetVersion = \"Excel 97\"\n Case 9:\n GetVersion = \"Excel 2000\"\n Case 10:\n GetVersion = \"Excel 2002\"\n Case 11:\n GetVersion = \"Excel 2003\"\n Case 12:\n GetVersion = \"Excel 2007\"\n Case 14:\n GetVersion = \"Excel 2010\"\n Case 15:\n GetVersion = \"Excel 2013\"\n Case 16:\n GetVersion = \"Excel 2016\"\n Case Else:\n GetVersion= \"Excel Unknown Version\u201d\n End Select\nEnd Function\n<\/code><\/pre>\nImportant Note: <\/h3>\n
VBA.Val(Application.Version) returns a number. Each version of the excel can be determined by the following mapping of Version Number and name. Same mapping I have put in the above code:
\n
\nDo not ask me why version number 13 is missing from the sequence \ud83d\ude42
\n <\/p>\n
Version Number<\/td>\n | Version Name<\/td>\n<\/tr>\n |
8<\/td>\n | Excel 97<\/td>\n<\/tr>\n |
9<\/td>\n | Excel 2000<\/td>\n<\/tr>\n |
10<\/td>\n | Excel 2002<\/td>\n<\/tr>\n |
11<\/td>\n | Excel 2003<\/td>\n<\/tr>\n |
12<\/td>\n | Excel 2007<\/td>\n<\/tr>\n |
14<\/td>\n | Excel 2010<\/td>\n<\/tr>\n |
15<\/td>\n | Excel 2013<\/td>\n<\/tr>\n |
16<\/td>\n | Excel 2016<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\nHow to use this function? <\/h3>\nStep 1. Copy the above code Have a nice weekend !!<\/p>\n<\/span>","protected":false},"excerpt":{"rendered":" Dear Friends, Usually while working on any of the VBA projects, it becomes important for me to first check the version of excel which user is using and based on that certain functionality of my tool may or may not work. For Example: If you have some sales data using more than 256 columns then […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1246,1674,1679,1675,1676],"tags":[],"class_list":["post-4638","post","type-post","status-publish","format-standard","hentry","category-macro","category-excel-macro-basics","category-excel-macro-beginner","category-excel-macro-for-beginners","category-excel-tips"],"yoast_head":"\n |