Calling the wrong macro

  • Thread starter Thread starter Philip
  • Start date Start date
P

Philip

Hi Folks,
Any help with this would be much appreciated:
I have two workbooks created in Excel 2000, Book A and Book B
Both work books contain a macro which have the same name: MyMacro1

MyMacro1 contains different code in each workbook
When I call MyMacro1 in Book A, Excel opens Workbook B and runs the code
within the Book B - MyMacro1

I can't figure out why this happening - has anyone any ideas please?
I've tried deleting both macros and recreating them independently - to no
avail!

TIA

Philip
 
I guess it depends on what you mean by Call MyMacro1. If you are doing it
with a menu button, then it is tied to a specifice macro - probably the one
in workbook B.
 
Thanks Tom,
Yes, you're right, I'm calling it from a toolbar button - I guess that must
make a difference. So I suppose my question should really be: How do I make
a toolbar and it's associated macros launced specific to a Workbook.

I've tried playing around with it but having created a toolbar it seems to
appear in all Workbooks? That suprises me a little

Thanks again for replying - I appreciate your help

Regards

Philip
 
Toolbars are at the application level. When you assign a macro to the
toolbar, it includes the specific workbook that contains the macro and this
does not change (nor does it adjust if you move that workbook outside of
excel). You would need to add code in the workbook activate event for the
specific workbooks where you want that behavior, that reassigns the macro --
assign the button's onaction property to the macro in that workbook.
 
Thanks Tom, I'd kinda hoped that it would work in much the same way as MS
Word - but it obviously doesn't
You have saved me from wasting a lot more of time though - thanks again.

Philip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top