There are basically three ways you can go about this. The first is to have
both the workbook that contains the sub and the workbook that needs to use
the sub open and use Application.Run to execute the code. E.g.,
Application.Run "'WorkbookWithSub.xls'!TheSubName"
Pay attention to the apostrophes. They are not necessary if your workbook
name does not contain spaces, but are necessary if the workbook name
contains spaces. In either case, they are harmless.
The second method is to create a reference from the workbook that needs to
use the sub to the workbook that contains the sub. In the workbook that
contains the sub, go to the Tools menu in VBA and choose "VBA Project
Properties". Change the name of the project to something meaningful, e.g.,
MyProject. Then open the workbook that needs to use the sub, go to to the
Tools menu in VBA, choose References, and select and check "MyProject" or
whatever you named the project. With this reference in place, you can call
the sub as if it resided in the same workbook. If there is the possibility
of a name collision (two subs with the same name), you can prefix the sub
name with the library name:
MyProject.MySub
Finally, you could put the sub into an Add-In and load that add-in via the
Add-Ins dialog on the Tools menu in Excel. With the add-in loaded, you can
call the sub directly as if it existed in the same workbook. Again, you can
avoid name collisions by including the project name of the add-in.
MyAddInProject.MySub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)