Grouped Shapes VBA

IGWright

New Member
Joined
Apr 15, 2007
Messages
40
Hello Everyone!

I've searched high and low for an answer on this, and still can't quite make it work.

I have a Workbook with many Grouped shapes. One of the problems I've been having is that when I change the focus of the Worksheet, the size of the Shapes change by increments. This seems to be some kind of flaw with the program.

It's not a big deal since the changes are small, but I've been looking into a code based solution. What I've got so far is:

Sub Shapes()
If Shape.Name = "Top" Then
.LockAspectRatio = msoFalse
.Height = 13
.Width = 13
.LockAspectRatio = msoTrue
End If
End Sub

In this case there are several Shapes named "Top". They are all Grouped. The Height and Width are supposed to be 0.18" and I find that if I set the .Height and .Width to 13, it sets those parameters to 0.18".

I can get this code to work for one Shape, but not multiple.

Any help here would be appreciated.

Thank-you,


Ian
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I suggest you record a macro.

Once shapes are grouped we cannot change them individually.

You may just need to change the size of the Group.
(select the group and look at name box top left of sheet)
 
Upvote 0
Thank-you for getting back!
This I've discovered through trial and error.
Any tier of Grouped Shapes CAN be accessed through VBA (2007).

If the Work Sheet contains 2 or more Groups or Shapes with the same name, the code below will access the Group or shape at the bottom on the Selection and Visibility pane only (in this case "Outside Diameter").

Sub Shapes()
ActiveSheet.Shapes("Outside Diameter").LockAspectRatio = msoFalse
ActiveSheet.Shapes("Outside Diameter").Height = 40
ActiveSheet.Shapes("Outside Diameter").Width = 40
ActiveSheet.Shapes("Outside Diameter").LockAspectRatio = msoTrue
End Sub

So at this point I'm looking for a way to get the Code to move through all the Groups or Shapes that match it's criteria.


Ian
 
Upvote 0
That occurred to me - that I should give each Shape a unique name.

I am having the same problem as crackjack in that when I record Macros, there's nothing Recorded.

Ian
 
Upvote 0
I can get this code to work for one Shape, but not multiple.

Not have time to do code. If you set a variable to include all shapes in a ShapeRange (search on this) you can change the whole lot in one go.
 
Upvote 0
Thank-you Brian.
I'm also thinking the AutoShapes may be more solid with 2010, in that they don't change size on their own (which was the case with 2007).


Ian
 
Upvote 0
Hi Ian,

1) I would suggest to install all service packs for Excel 2007.

2) All shapes even items of the grouped one are accessible via VBA:
Rich (BB code):

Sub Test()
  Dim Shp1 As Shape, Shp2 As Shape
  On Error Resume Next
  For Each Shp1 In ActiveSheet.Shapes
    Debug.Print Shp1.Name, Shp1.Width, Shp1.Height
    For Each Shp2 In Shp1.GroupItems
      Debug.Print vbTab & Shp2.Name, Shp2.Width, Shp2.Height
'      If Shp2.Name = "MyShapeName" Then
'        Shp2.Width = 36
'        Shp2.Height = 258
'      End If
    Next
  Next
End Sub
Regards,
Vladimir
 
Upvote 0

Forum statistics

Threads
1,221,476
Messages
6,160,058
Members
451,615
Latest member
soroosh

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