Selecting more the one shape

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Selecting more the one shape

Post by ABabeNChrist »

I have a piece of code that I use to toggle the first shape, Visible=True or False
How would I adapt this code to do more the one shape at a time?

Code: Select all

Private Sub CommandButton5_Click()
    If ActiveSheet.Shapes(1).Visible = True Then
        ActiveSheet.Shapes(1).Visible = False
    ElseIf ActiveSheet.Shapes(1).Visible = False Then
        ActiveSheet.Shapes(1).Visible = True
    End If
End Sub

Jim Cone
StarLounger
Posts: 78
Joined: 18 Feb 2010, 01:44

Re: Selecting more the one shape

Post by Jim Cone »

Depending on what you actually need, here are a couple of ways...
'--
'Just the ones you want...
Sub HideAndSeek_1()
Dim shps As Shapes
Dim shpRng As ShapeRange

Set shps = ActiveSheet.Shapes
Set shpRng = shps.Range(Array(2, 4))
shpRng.Visible = Not shpRng.Visible
End Sub

'Do all shapes...
Sub HideAndSeek_2()
Dim shps As Shapes
Dim blnVis As Boolean
Dim N As Long

Set shps = ActiveSheet.Shapes
blnVis = Not shps(1).Visible
For N = 1 To shps.Count
shps(N).Visible = blnVis
Next
End Sub
'--
Jim Cone
Portland, Oregon USA
https://goo.gl/IUQUN2" onclick="window.open(this.href);return false; (Dropbox)
Last edited by Jim Cone on 14 Oct 2016, 14:08, edited 1 time in total.

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Selecting more the one shape

Post by ABabeNChrist »

Thank you Jim
They all worked great