akaCAV
akaCAV

Reputation: 1

Show and Hide img using vba

I have to show or hide an image on different sheets. Can anyone help me?

Here is my vba code:

Sub showhide()
    With ActiveSheet.Shapes("Picture 1")
    .Visible = Not .Visible
    End With
End Sub

Upvotes: 0

Views: 6005

Answers (2)

Gino
Gino

Reputation: 176

I'd rather have a foreach statement where you can loop trough your imgs and set them as you please

Set shapeList = ActiveSheet.Shapes
        For Each shp In shapeList
            If shp.Visible = true Then
                shp.Visible=false
           else
                shp.Visible=false
            End If
        Next shp

Of course you have to launch your event on each page with a button or something. Or even when the page loads set the img to this function

Upvotes: 0

Gabe
Gabe

Reputation: 1183

Just check if is already visible or not and do the oppsite:

Sub showhide()
 With ActiveSheet.Shapes("Picture 1") 
  If .Visible = False Then
    .Visible = True
  Else
    .Visible = False        
  End With
End Sub

Upvotes: 2

Related Questions