简体   繁体   中英

Hide/unhide multiple shapes Excel VBA

I am very new to excel VBA & macros and I am trying to do something that I think is very simple, but I cannot for the life of me figure it out.

I have a shape ("shape 1") that when clicked should show/unhide two shapes ("shape 2" and "shape 3").

By default "shape 2" and "shape 3" should be hidden and only appear when "shape 1" is selected.

Any help will be much appreciated, remembering I am a complete novice here!

Edit:

I have managed to use the below, essentially a copy paste from here , I dont know what it means but it works for the single button. I cant figure out how to extend the code to include multiple objects being shown/hidden. An example of a second object to be shown/hidden at the same time as "july_2022" is "august_2022".

Public HIDE As Boolean

Sub fy ()
ActiveSheet.Shapes("july_2022").Visible = HIDE
If ActiveSheet.Shapes("july_2022").Visible = False Then
HIDE = True
Else
HIDE = False
End If
End Sub

ActiveSheet.Shapes("july_2022").Visible = HIDE is the part that sets the visibility of a shape ( july_2022 ). Another identical line but with something other than july_2022 would affect a second shape. The rest of the code ( If.. Then.. Else.. End If ) could be replaced with HIDE=Not(HIDE) .

For example, the following code when run will 'toggle' the visibility of two shapes on the Active Sheet called 'Shape2' and 'Shape3'.

Public HIDE As Boolean

Sub fy()
    ActiveSheet.Shapes("Shape2").Visible = HIDE
    ActiveSheet.Shapes("Shape3").Visible = HIDE
    HIDE = Not (HIDE)
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM