Is there a way to hide all of one type of shape? For example, I have a project management sheet with connectors and boxes with text. I would like all connectors to appear and disappear. Is this possible or would the code have to be for each individual shape name?
You can determine the type of shape with the Shape.AutoShapeType property, and then use the Enum MsoAutoShapeType to compare the shape type: Sub test()
Dim sh As Shape
For Each sh In Sheet1.Shapes If sh.AutoShapeType = MsoAutoShapeType.msoShapeRectangle Then sh.Visible = msoFalse End If Next sh
This is brilliant, thanks. How could I hide/unhide more than one shape at a time? I'm trying: Me.Shapes("Green1", "Green2").visible=msoTrue but it's not working :(
For a simple code you can write: Sheet1.Shapes.Range(Array("Rectangle 1", "Rounded Rectangle 2")).Visible = msoFalse You can make it a bit more robust by creating a private sub and passing on just the shapes names in an array: Sub MainSub()
Dim ShapesList As Variant ShapesList = Array("Rectangle 1", "Rounded Rectangle 2")
Call HideShapes(ShapesList, Sheet1) 'Sheet1 is the codename visible in VBE
End Sub Private Sub HideShapes(ShapeList As Variant, TargetWorksheet As Worksheet)
Dim ShapeName As Variant Dim IndividualShape As Shape
For Each ShapeName In ShapeList For Each IndividualShape In TargetWorksheet.Shapes If IndividualShape.Name = ShapeName Then IndividualShape.Visible = msoFalse End If Next IndividualShape Next ShapeName
top..very good..
Thank you, this covered exactly what I was looking for
It was very helpful sir, thanks a lot for your wounderful effort
Is there a way to hide all of one type of shape? For example, I have a project management sheet with connectors and boxes with text. I would like all connectors to appear and disappear. Is this possible or would the code have to be for each individual shape name?
You can determine the type of shape with the Shape.AutoShapeType property, and then use the Enum MsoAutoShapeType to compare the shape type:
Sub test()
Dim sh As Shape
For Each sh In Sheet1.Shapes
If sh.AutoShapeType = MsoAutoShapeType.msoShapeRectangle Then
sh.Visible = msoFalse
End If
Next sh
End Sub
But can i show and hide a command button if a cell value si 'x' for example?? If u show me..i will send u some money on Revolut
This is brilliant, thanks.
How could I hide/unhide more than one shape at a time?
I'm trying: Me.Shapes("Green1", "Green2").visible=msoTrue
but it's not working :(
For a simple code you can write: Sheet1.Shapes.Range(Array("Rectangle 1", "Rounded Rectangle 2")).Visible = msoFalse
You can make it a bit more robust by creating a private sub and passing on just the shapes names in an array:
Sub MainSub()
Dim ShapesList As Variant
ShapesList = Array("Rectangle 1", "Rounded Rectangle 2")
Call HideShapes(ShapesList, Sheet1) 'Sheet1 is the codename visible in VBE
End Sub
Private Sub HideShapes(ShapeList As Variant, TargetWorksheet As Worksheet)
Dim ShapeName As Variant
Dim IndividualShape As Shape
For Each ShapeName In ShapeList
For Each IndividualShape In TargetWorksheet.Shapes
If IndividualShape.Name = ShapeName Then
IndividualShape.Visible = msoFalse
End If
Next IndividualShape
Next ShapeName
End Sub