• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Hide and unhide hrouped shapes

kenducot

New Member
I have a group of shapes which I hide and unhide using vb code. However, the code does not work when new shapes are added to the group because the name of the new grouped shapes changes but my codes specifically refers only to the name of the previous grouped shapes. Is there a general code that will address this issue? Thank you for your help. Please see attached file.

Here's my code:

Code:
Sub RoundedRectangle4_Click()

    With ActiveSheet.Shapes("Rounded Rectangle 4").TextFrame2.TextRange.Characters
        If .Text = "Hide Floor Plan" Then
            .Text = "Show Floor Plan"
            ActiveSheet.Shapes("group 5").Visible = False
        Else
            .Text = "Hide Floor Plan"
            With ActiveSheet.Shapes("Rounded Rectangle 4")
            ActiveSheet.Shapes("group 5").Left = .Left + .Width
            ActiveSheet.Shapes("group 5").Top = .Top + .Height
            ActiveSheet.Shapes("group 5").Visible = True
            End With
        End If
    End With
End Sub
 

Attachments

  • Hide and unhide grouped shapes.xlsm
    16.7 KB · Views: 21
Last edited by a moderator:
kenducot
How many times should someone teach You how to use those code - tags?
 
If one of the shapes is always part of the group, you can refer to its ParentGroup property to get the group shape.
 
Which problem ! As you just have to update the group name in the code​
or better just rename the group after adding a new shape​
or mod your code just following post #3 (see VBA inner help), very not an issue … :rolleyes:
 
Let's say Rectangle 3 is always part of the group. In that case, instead of:

Code:
ActiveSheet.Shapes("group 5").Visible = False

you can use:

Code:
ActiveSheet.Shapes("Rectangle 3").Parentgroup..Visible = False
 
Back
Top