Microsoft KB Archive/213233

= XL2000: Grouped Drawing Objects Run Separate Macros =

Article ID: 213233

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213233





SYMPTOMS
When you assign different macros to drawing objects, group two or more of the drawing objects on a worksheet, attempt to create a group macro, and then click an object in the group, Microsoft Excel runs the macro that is assigned to the object you clicked, as in the following example:  Start Excel. Press ALT+F11 to start the Visual Basic editor. On the Insert menu, click Module.  In the module sheet, type the following code: Sub Oval_Code MsgBox "This is an oval." End Sub

Sub Rectangle_Code MsgBox "This is a rectangle." End Sub

Sub Group_Code MsgBox "This is a group." End Sub  Press ALT+F11 to return to Excel. On the Drawing toolbar, click Oval, and then draw an oval on the worksheet.

NOTE: If the Drawing toolbar is not visible, point to Toolbars on the View menu, and then click Drawing. On the Drawing toolbar, click Rectangle, and then draw a rectangle on the worksheet.</li> Right-click the oval, and then click Assign Macro on the shortcut menu.</li> In the Assign Macro dialog box, click Oval_Code, and then click OK.</li> Right-click the rectangle and then click Assign Macro on the shortcut menu.</li> In the Assign Macro dialog box, click Rectangle_Code, and then click OK.</li> Press and hold CTRL+SHIFT, click the rectangle, and then click the circle.

Both objects are selected.</li> On the Draw menu, click Group.</li> Right-click either object to select the group, and then click Assign Macro on the shortcut menu.</li> In the Assign Macro dialog box, click Group_Code, and then click OK.</li> Click outside the group to unselect the group.</li> Click the rectangle.

Note that the macro assigned to the rectangle appears, not the macro assigned to the group.</li></ol>

<div class="cause_section">

CAUSE
This behavior occurs because you cannot assign a macro to a group of objects if the objects already are assigned macros. When you click an object that belongs to a group it will run any macro that is assigned to that specific object.

<div class="resolution_section">

RESOLUTION
To resolve this issue, do not assign individual macros to objects that you plan to group. You can assign a macro to a group if the objects within the group are not already assigned macros, as in the following example: <ol> Start Excel.</li> Press ALT+F11 to start the Visual Basic editor.</li> On the Insert menu, point to Macro, and then click Macros.</li>  In the module sheet, type the following code: Sub Group_Code MsgBox "This is a group." End Sub </li> Press ALT+F11 to return to Excel.</li> <li>On the Drawing toolbar, click Oval, and then draw an oval on the worksheet.</li> <li>On the Drawing toolbar, click Rectangle, and then draw a rectangle on the worksheet.</li> <li>Press and hold SHIFT, click the rectangle, and then click the oval.

Both objects are selected.</li> <li>On the Draw menu, click Group.</li> <li>Right-click either object to select the group, and then click Assign Macro on the shortcut menu.</li> <li>In the Assign Macro dialog box, click Group_Code, and then click OK.</li> <li>Click outside the group to unselect the group.</li> <li>Click the rectangle.

Note that the group macro is called.</li></ol>

<div class="references_section">