Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem accessing visual basic subs from another workbook

Status
Not open for further replies.

vincent76

Programmer
Oct 23, 2001
8
CA
Hi;

I have an excel workbook that calls a sub located in another workbook. I use:
Application.Run "C:/ExcelFile.xls!subname", argument1

For some reason whenever I execute this code it gives me a run-time error 1004 ( the macro 'C:/ExcelFile.xls!subname' ) cannot be found.

I verified the path and the filename and the sub they all exist. I thought that the sub was in a form and I know that you cannot call procedures in a form, but it's not, it is in a module. I have no clue why VB couldn't find it? The spelling and the path are correct.

Any help or insight would be much apreciated.
 
Hiya,

Inefficient, but try putting the function/sub in the form itself. I don't think that functions/subs in modules can be used if you access the form externally.

It'll prove it either way.

Regards,

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Hi Darrylle;

Thanks for your response!

I created 2 workbooks w1.xls and w2.xls.

In w1 I inserted a user form and inserted a sub called hello:

sub hello()
msgbox ("hello from w1!")
end sub


In w2 I inserted a module and inserted a sub callw1:

sub callw1()
application.Run "C:\Documents and Settings\vince\Desktop\w1.xls!hello"
end sub


I then pressed Alt+F8 and chose Macro callw1 and ran it. I got the following error:
run-time error 1004:
The macro 'C:\Documents and Settings\vince\Desktop\w1.xls!hello' cannot be found


I tried the same thing but put the hello sub in a module it gave me the same error. I even tried to prefix the macro name with the module ...w1.xls!Module1.hello and still didn't work. What am I doing wrong?? I just need to call a sub from another workbook.. this should work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top