Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: Grouped Drawing Objects Run Separate Macros


View products that this article applies to.

This article was previously published under Q213233

↑ Back to the top


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:
  1. Start Excel.
  2. Press ALT+F11 to start the Visual Basic editor.
  3. On the Insert menu, click Module.
  4. 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
    					
  5. Press ALT+F11 to return to Excel.
  6. 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.
  7. On the Drawing toolbar, click Rectangle, and then draw a rectangle on the worksheet.
  8. Right-click the oval, and then click Assign Macro on the shortcut menu.
  9. In the Assign Macro dialog box, click Oval_Code, and then click OK.
  10. Right-click the rectangle and then click Assign Macro on the shortcut menu.
  11. In the Assign Macro dialog box, click Rectangle_Code, and then click OK.
  12. Press and hold CTRL+SHIFT, click the rectangle, and then click the circle.

    Both objects are selected.
  13. On the Draw menu, click Group.
  14. Right-click either object to select the group, and then click Assign Macro on the shortcut menu.
  15. In the Assign Macro dialog box, click Group_Code, and then click OK.
  16. Click outside the group to unselect the group.
  17. Click the rectangle.

    Note that the macro assigned to the rectangle appears, not the macro assigned to the group.

↑ Back to the top


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.

↑ Back to the top


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:
  1. Start Excel.
  2. Press ALT+F11 to start the Visual Basic editor.
  3. On the Insert menu, point to Macro, and then click Macros.
  4. In the module sheet, type the following code:
    Sub Group_Code()
       MsgBox "This is a group."
    End Sub
    						
  5. Press ALT+F11 to return to Excel.
  6. On the Drawing toolbar, click Oval, and then draw an oval on the worksheet.
  7. On the Drawing toolbar, click Rectangle, and then draw a rectangle on the worksheet.
  8. Press and hold SHIFT, click the rectangle, and then click the oval.

    Both objects are selected.
  9. On the Draw menu, click Group.
  10. Right-click either object to select the group, and then click Assign Macro on the shortcut menu.
  11. In the Assign Macro dialog box, click Group_Code, and then click OK.
  12. Click outside the group to unselect the group.
  13. Click the rectangle.

    Note that the group macro is called.

↑ Back to the top


References

For more information about grouping objects, click Microsoft Excel Help on the Help menu, type group drawing objects in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB213233, kbprogramming, kbprb

↑ Back to the top

Article Info
Article ID : 213233
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 302