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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem executing a macro in another open Workbook 1

Status
Not open for further replies.

Zac5

Programmer
Jan 30, 2003
75
US
I want to execute a macro called "Main" held in second workbook from macro in current workbook

current workbook snippet is as follows:

Dim second_wb As Workbook
Set second_wb = ActiveWorkbook

Application.Run (second_wb!Main)

Above line fails, I think I have the syntax wrong, any ideas please, thanks in advance.
 
Have you tried this ?
Application.Run second_wb.Name & "!Main"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Its a somewhat better result, however now I get a "run-time error 1004: The macro 'second macro.xls!Main' cannot be found"

Could it be that the macro is not enabled when the second workbook is opened through the primary macro - no idea???
 
You really have an embedded space in your workbook's name ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,

Yes there is a space in the workbook's name. Any ideas?

Thanks.
 
Perhaps this ?
Code:
Application.Run "'" & second_wb.Name & "'!Main"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How can "second_wb" be your ActiveWorkbook? Wouldn't that just make "second_wb" your current workbook?

_________________
Bob Rashkin
 
PHV - Tried putting it in quotes as you said, but now gives a run-time error '424' Object required at the same place.

Bob - I don't think what you are suggesting is causing the problem, thanks nevertheless.
 
Hi PHV,

Apologies, your last post that recommeded adding the quotes has resolved it. I made a small mistake with the quotes whilst adding them.

Thanks a lot for your help once again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top