Naming / Grouping Objects

jhol4

Board Regular
Joined
Nov 18, 2002
Messages
71
Hi there

I was wondering if anyone can help me out with naming an object in a macro.

Basically, the macro will create a couple of shapes which I want to be able to group together. The problem is that depending on how many times the macro is run, the name of each object will change (eg. "Rectangle 5") Therefore, when I try to group the shapes, it will not work because I can't refer the each shape as I don't know what the name of each shape is going to be.

If anyone knows a way around this it would be greatly appreciated.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hello,

Try this macro. Post back if something's not clear.

<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> GroupEm()

    <SPAN style="color:darkblue">Dim</SPAN> Shape1 <SPAN style="color:darkblue">As</SPAN> Shape, Shape2 <SPAN style="color:darkblue">As</SPAN> Shape

    <SPAN style="color:darkblue">Set</SPAN> Shape1 = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 204.75, 135#, 177#, 57#)
    <SPAN style="color:darkblue">Set</SPAN> Shape2 = ActiveSheet.Shapes.AddShape(msoShapeCube, 302.25, 91.5, 113.25, 89.25)

    Sheets("Sheet1").Shapes.Range(Array(Shape1.Name, Shape2.Name)).Group
    
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN>
</FONT>
 
Upvote 0
Thanks dk

I also found out that you can name shapes in the same way that you would name a range....so simple, but it took me ages to figure it out!!!
 
Upvote 0

Forum statistics

Threads
1,221,706
Messages
6,161,406
Members
451,702
Latest member
Kc3475

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