Solved

Problem executing a macro in another open Workbook

Posted on 2009-04-06
8
294 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 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
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!

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

756 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