Solved

Problem executing a macro in another open Workbook

Posted on 2009-04-06
8
286 Views
Last Modified: 2012-05-06
I want to execute a macro called "Main" held in second workbook from macro in current workbook

current workbook code snippet is as follows:

Dim second_wb As Workbook
Set second_wb = ActiveWorkbook

Application.Run second_wb.Name & "!Main"

I get a "run-time error 1004: The macro 'second macro.xls!Main' cannot be found".

Any ideas anyone please?

Thanks
0
Comment
Question by:Zac5
  • 4
  • 4
8 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 125 total points
ID: 24076817
Zac5 said:
>>Any ideas anyone please?

1) Make sure that Main is not declared as a Private macro, and/or that you have not used a module declaration
Option Private Module.

2) Change the call to:

Application.Run "'" & second_wb.Name & "'!Main"
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24076824
Zac5,

Another thing to check:  is Main in a "regular" module, or is it in a class/UserForm/sheet/ThisWorkbook
module?

Regards,

Patrick
0
 

Author Comment

by:Zac5
ID: 24076919
Hi Patrick,

thanks for your reply, my guess would be a regular module looking at the tree structure on the left of Microsoft VB Editor, but I'm not sure, how can I tell you for certain?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24076960
Zac5 said:
>>my guess would be a regular module looking at the tree structure on the left of Microsoft VB Editor, but I'm
>>not sure, how can I tell you for certain?

If the module shows up under the "Modules" node, and not under the Forms, Class Modules, or Microsoft Excel
Objects nodes, then it's a regular module.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24076963
Zac5,

BTW, did you change the call to wrap the workbook name in single quotes, as I demonstrated in my first post?

Regards,

Patrick
0
 

Author Comment

by:Zac5
ID: 24077320
I had missed your first post on adding the quotes and tried it now, but still no luck unfortunately, still fails but this time with an error "Object required".  I have put it back to the way it was for now.
0
 

Author Comment

by:Zac5
ID: 24077396
and it is a regular module.
0
 

Author Closing Comment

by:Zac5
ID: 31566987
Hi Patrick,
Thanks you resolved it in your first post! As you said, the quotes were needed. I made a mistake whilst adding your line to my code, I forgot to replace "second_wb" with the actual name in my code, hence the "obect required" error :-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now