?
Solved

Problem executing a macro in another open Workbook

Posted on 2009-04-06
8
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 500 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 93

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 93

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
 
LVL 93

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

718 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