简体   繁体   English

隐藏/取消隐藏多个形状Excel VBA

[英]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.我对 excel VBA 和宏非常陌生,我正在尝试做一些我认为非常简单的事情,但我一生都无法弄清楚。

I have a shape ("shape 1") that when clicked should show/unhide two shapes ("shape 2" and "shape 3").我有一个形状(“形状 1”),单击时应显示/取消隐藏两个形状(“形状 2”和“形状 3”)。

By default "shape 2" and "shape 3" should be hidden and only appear when "shape 1" is selected.默认情况下,“shape 2”和“shape 3”应该是隐藏的,只有在“shape 1”被选中时才会出现。

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".与“july_2022”同时显示/隐藏的第二个对象的示例是“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 ). ActiveSheet.Shapes("july_2022").Visible = HIDE是设置形状可见性的部分( july_2022 )。 Another identical line but with something other than july_2022 would affect a second shape.另一条相同的线,但不是july_2022会影响第二个形状。 The rest of the code ( If.. Then.. Else.. End If ) could be replaced with HIDE=Not(HIDE) .其余代码( If.. Then.. Else.. End If )可以替换为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'.例如,以下代码在运行时将“切换”活动工作表上名为“Shape2”和“Shape3”的两个形状的可见性。

Public HIDE As Boolean

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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