How To Hide Shapes and Images in Excel with VBA | Excel VBA

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ม.ค. 2025

ความคิดเห็น • 8

  • @edsonpereira8997
    @edsonpereira8997 2 ปีที่แล้ว +2

    top..very good..

  • @herrdaveed
    @herrdaveed ปีที่แล้ว

    Thank you, this covered exactly what I was looking for

  • @sigmatabs9814
    @sigmatabs9814 2 ปีที่แล้ว

    It was very helpful sir, thanks a lot for your wounderful effort

  • @pattywyslobocka9682
    @pattywyslobocka9682 2 ปีที่แล้ว

    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?

    • @AntrikshSharma
      @AntrikshSharma  2 ปีที่แล้ว

      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

  • @bookmaster3699
    @bookmaster3699 2 ปีที่แล้ว

    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

  • @holisqueisequehase5054
    @holisqueisequehase5054 10 หลายเดือนก่อน

    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 :(

    • @AntrikshSharma
      @AntrikshSharma  9 หลายเดือนก่อน

      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