Grouping Objects

NextYearSox

Active Member
Joined
Oct 24, 2003
Messages
287
I have a number of shapes that I am using as buttons (hotspots) to launch various subroutines (basically, they are being used as sorting buttons). I have these shapes grouped together such that they maintain their physical proximity to each other.

When each button is clicked, I'd like it to be highlighted (i.e., the background is turned yellow, or the text is bold, etc.). However, because they are grouped together, I am unable to do so within VB (I can manually). I thought that I might get around this problem by: (1) ungrouping the buttons; (2) highlighting the button; and (3) re-grouping the buttons. However, each time I regroup, the name of the group changes; so this doesn't seem to be a workable solution.

Any ideas on how to skin this particular cat?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
If it's only the name that concerns you, assign it to a variable before ungrouping. Then after regrouping rename it to the original name.
 
Upvote 0
VBE - F2 key (Object explorer). Pick shape in the classes pane and then GroupItems in the members pane and tap your buddy, the F1 key. I think that'll get ya whatcha need.
 
Upvote 0
The trick is to name your shapes, then use an Array to hold the group then you can unGroup and re-group using the array as indicated here:


Sub myTest()

Set myDocument = Worksheets(1)

With myDocument.Shapes
.AddShape(msoShapeCan, 50, 10, 100, 200).Name = "shpOne"
.AddShape(msoShapeCube, 150, 250, 100, 200).Name = "shpTwo"

With .Range(Array("shpOne", "shpTwo")).Group
.Fill.PresetTextured msoTextureBlueTissuePaper
.Rotation = 45
.ZOrder msoSendToBack
End With
End With

For Each s In myDocument.Shapes
s.Ungroup
Next
End Sub
 
Upvote 0
Fiddlesticks. If the items in question are truly shapes then all's ya need is:
Code:
    ActiveSheet.Shapes("MyShapeGroup").GroupItems(2).Fill.ForeColor.RGB = RGB(255, 0, 0)
    ActiveSheet.Shapes("MyShapeGroup").GroupItems(1).Fill.ForeColor.RGB = RGB(196, 196, 196)

However, having said that; I can't get this to work at all at changing the fill colors on actual buttons.
 
Upvote 0
This sounds like the general idea. I'm having some problems implementing this due to ignorance, I'm sure.

My code looks like the following:

Sub ButtonName()
ActiveSheet.Shapes("Rectangle 65").Name = "SortA"
ActiveSheet.Shapes("Rectangle 60").Name = "SortB"
ActiveSheet.Shapes("Rectangle 62").Name = "SortC"
ActiveSheet.Shapes("Rectangle 63").Name = "SortD"
ActiveSheet.Shapes("Rectangle 64").Name = "SortE"
ActiveSheet.Shapes("AutoShape 67").Name = "Background"

With .Range(Array("SortA", "SortB", "SortC", "SortC", "SortE", "Background")).Group
End Sub

The last shape ("Background") is the shape I want on the bottom (i.e., Order/Send to back). The other 5 shapes will be superimposed on top and separate from each other - so it doesn't matter their order.

The last line (with .Range(Array....) isn't doing the job. What code should I use to group these and ungroup these?

Thanks
 
Upvote 0
Joe's line is inside a WITH/END WITH structure, specifically
Code:
with mydocument.shapes
which is why that particular line begins with a period. My guess is that your line is not within a WITH structure.
 
Upvote 0
I've solved the group question with the following code:

ActiveSheet.Shapes.Range(Array("SortA", "SortB", "SortC", "SortD", "SortE", "Background")).Group

Everytime I group these, the new group has a new name (i.e., Group 75, then Group 76, etc.).

Is there a way to select the group without knowing it's name?
Is there a way to reset the group number?
 
Upvote 0
You can assign the name when ya group 'em
Code:
ActiveSheet.Shapes.Range(Array("rectangle 1", "rectangle 2", "rectangle 3")).Group.Name = "PickelBarrel"
 
Upvote 0
'Array code here, then

Selection.ShapeRange.Group.Select
Selection.Name = "myShpGroup1"

I like Greg's better!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top