Solved

Problem executing a macro in another open Workbook

Posted on 2009-04-06
8
291 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

813 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

8 Experts available now in Live!

Get 1:1 Help Now