Article ID: 106008 - Last Review: October 11, 2006 - Revision: 2.2 Open Subroutines Run Before Referenced SubroutinesThis article was previously published under Q106008 On This PageSUMMARY
In Microsoft Excel, if you call a subroutine (for example, TestSub) from
another Visual Basic subroutine, Microsoft Excel will search for the
subroutine in the current workbook and then it will search any libraries
and/or workbooks to which the current workbook has references (these
references will be searched in top-to-bottom order as they appear in the
References dialog box).
Microsoft Excel will run the subroutine from the first location where it is found. This is by design. MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. Steps to Reproduce Behavior
For example, if you follow the steps in the "Steps to Reproduce Behavior Section" above, you create references to both BRAVO.XLS and CHARLIE.XLS. The first time the Starter subroutine is run (step 14), Microsoft Excel finds the TestSub subroutine in ALPHA.XLS and runs it. The second time the Starter subroutine is run (step 16), Microsoft Excel does not find the TestSub subroutine in ALPHA.XLS (because it has been deleted). It then checks the referenced libraries and modules for the subroutine. The subroutine is first found in BRAVO.XLS, and so Microsoft Excel runs the TestSub subroutine located there. For more information on creating references and running subroutines located in other workbooks, see the "Visual Basic User's Guide," Chapter 4. REFERENCES
For additional information about getting help with Visual Basic for
Applications, please see the following article in the Microsoft Knowledge
Base:
163435
(http://support.microsoft.com/kb/163435/EN-US/
)
VBA: Programming Resources for Visual Basic for Applications
| Article Translations
|


Back to the top
