I have two Excel Workbooks open A & B. Both have VB subroutines. I have A activated and am running Sub "a1" how can I from "a1" call and run Sub "b1" that resides in Workbook B? What I currently have to do is put a copy of "b1" in "a1".
You could also use an add-in created from workbook A to be available in workbook B, or save workbook A's procedure as a project. If the above method does not work, let me know and I'll post info on the add-in or project.
Both workbooks are in same folder, but that didn't help. The error I get is 1004, but this is too general. The example given for the RUN method when the F1 key is pressed ---is returning an argument from a macro or function. I can see no difference (from your example) in the construct of the sample statements. The test subroutines used are below
Sub Test()
Workbooks("Book2.xls").Activate
Application.Run "'Book2.xls'!Test2" End Sub
Sub Test2() Sheets("Sheet1").Range("B4") = 7 End Sub
Neither the Workbooks or the Worksheets are protected.
When I use the F1 key on error message the example returned is a function or macro that returns an argument not a sub which I am using. Does that shed any light? I feel badly using your time on this issue. I can use a work around but your approach seems so much more powerful that I wanted to use it in other applications.
Can you tell me in more detail what it is you're trying to accomplish? This code works on my Excel 2003 and 2007. Maybe by knowing what you're trying to do, I'll come up with a solution.
If possible, could you attach the files to an email for me to look at?
abach
1728 Posts
965
1
Posted January 31st, 2009 04:00
The easiest way is to have both workbooks open, then use the following:
Application.Run "'WorkbookWithSub.xls'!TheSubName"
You could also use an add-in created from workbook A to be available in workbook B, or save workbook A's procedure as a project. If the above method does not work, let me know and I'll post info on the add-in or project.