3
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 2")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 2")).Visible
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 3")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 3")).Visible
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 4")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 4")).Visible
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 5")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 5")).Visible

This is the sample of code macro that i use

i want to know how we can on run this code to hide only rectangle 1 line

like

For i = 1 To ActiveSheet.Shapes.Count
    ActiveSheet.Shapes.Range(Array("Rounded Rectangle *")).Visible = _ 
    Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle *")).Visible
Next i

I just dont know how to simplify correctly

4

1 回答 1

2

你不远了,这就是如何使用循环来遍历所有Rounded Rectangles

Dim i As Long
For i = 1 To ActiveSheet.Shapes.Count
    ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible = _
    Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible
Next i

请注意如何"Rounded Rectangle " & i
"Rounded Rectangle 1"
"Rounded Rectangle 2"
"Rounded Rectangle n"where替换n = i(表示循环运行的次数)


因此,如果您只想隐藏第一个,则在循环 注释Rounded Rectangle 1中添加If/else语句:此代码将永远不会显示第一个在显示所有其他的之间切换。如果您想始终显示它们,则只需在 else 语句中分配true
Rounded Rectangle 1

Dim i As Long
For i = 1 To ActiveSheet.Shapes.Count
    If i = 1 Then
        ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible = False
    Else
        ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible = _
        ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible
    End If
Next i
于 2013-06-28T08:12:57.823 回答