简体   繁体   中英

Can't assign macro in excel

I am having some trouble with macros in my excel workbook. I have a couple of auto-shapes on one of my sheets which are grouped together for drawings. 2 of these have macros assigned to them (as 'kitchen - 1.xls'!but59 and 'kitchen - 1.xls'!but60 ), but I can't seem to assign macros to the other 2 shapes. I have tried right clicking on the shape, Assign Macro , select the macro that I wan to assign to, and then click Okay . But when I double check which macro it calls, it still calls Baseunits_fbase3_3_Click - it creates this new macro and I can't seem to force it to use my already written macro. Is there any other way to assign the macro that I need?


EDIT: I am kind of hoping that there is perhaps a way to assign the macro via VBA, but I can't see any reference to that in the online VBA reference anywhere. Does anyone know if this is possible?

Okay, my solution to this (a bit of a hack, but it works) was to simply create a rectangle shape, give it no fill and no line, order it to the front, place it over the shape that the user has to click, and then assign the macro to this front shape.

Still no idea why I can't assign the macro to the original shapes, though - there has been quite a few like that now.

EDIT: I worked out how to assign the macro - I had to select the group, and then also select each of the shapes in the group , and assign the macro to all these selected shapes. This seemed to work consistently, and was also necessary in a number of cases for porting to Excel 2007.

I take it this is for Excel 2003??

What you are doing sounds correct. It sounds like there is a problem with the Grouping.

You have two options:

  1. In Baseunits_fbase3_3_Click , call the 'kitchen - 1.xls'!but59

  2. Delete all the objects in that group, and try again

The first option is a bit excessive and the second is a little drastic.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM