Written by Allen Wyatt (last updated May 27, 2023)
This tip applies to Excel 97, 2000, 2002, and 2003
Mark is in a work environment that uses two versions of Excel?2002 and 2003. A problem arises when he opens a workbook with a macro in Excel 2003, which installs the VB library of Office 11, and then later someone tries to open the same workbook in Excel 2002, which gives an error when the macro tries to run because it cannot find the correct VBA library reference. Mark knows he can manually correct this by going to the VB editor and clearing the reference to the missing VBA library, but he wonders if there is any way to have the workbook check the Excel version automatically and update the VBA library reference accordingly.
One way to deal with this is to create and save the workbook using the earlier version of Excel. When it is opened in the later version of Excel, the reference to the VBA library will be automatically updated. Excel does the updates going to later versions, but it doesn?t do them going to earlier versions.
This means, however, that even if the workbook is created in the earlier version of Excel, once it is opened and subsequently saved in the later version of Excel, users of the earlier version will have problems opening it.
The solution, according to some sources, is to resort to what is known as ?late binding.? This simply means that the macro is written so that it looks up specific functions only during run-time, not when the macro is saved. This is referenced a bit in the following Microsoft Knowledge Base article:
http://support.microsoft.com/?kbid=244167
You can try late binding techniques by opening the VBA editor and removing any references previously established. Then add code similar to the following near the start of your macro:
If Application.Version = "10.0" Then 'Excel 2002 Dim oExcel As Object 'Apply late binding Set oExcel = CreateObject("Excel.Application") End If If Application.Version = "11.0" Then 'Excel 2003 ' ' Add whatever references you want for Excel 2003 ' End If
At the end of the macro make sure that you set any defined objects (such as oExcel) to Nothing. A good example of code that is more robust than what is presented here can be found in these articles:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=267 http://www.vbaexpress.com/kb/getarticle.php?kb_id=272
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3340) applies to Microsoft Excel 97, 2000, 2002, and 2003.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Excel allows you to use worksheet functions from within macros. This is helpful, especially when you are trying to ...
Discover MoreMacros that run automatically when you open or close a workbook are quite helpful. You may not want them to run, however, ...
Discover MoreNeed to gather some information about the drives on a system? It can be pretty easy to do using a macro, as shown in this ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments