Excel ActiveSheet.数组.范围(MyArray).选择

vatpfxk5  于 7个月前  发布在  其他
关注(0)|答案(1)|浏览(83)

我想在指定的页码上选择具有指定条件的形状,将它们一次选择到数组中,并将它们分组,但系统显示“ActiveSheet. Array.Range(MyArray).Select”的错误消息

Sub group_all() 

    Dim X, x_count, x_start, x_end As Integer
    Dim S As Shape
    Dim MyArray
    Dim n As Integer
    
    With ActiveSheet

        X = 2
    
         If X = 1 Then
            x_start = 1
        Else:
            x_start = .HPageBreaks(X - 1).Location.Row 'x start row
         End If
         x_end = .HPageBreaks(X).Location.Row - 1 'X end row
        '------------------------------------------------------------------------------------------------------
        MyArray = Array("")

        For Each S In .Shapes
        
            If S.Type = msoGroup Then S.Ungroup

        Next S
        
        n = 0
        
        For Each S In .Shapes

            If (S.Top > Cells(x_start, 10).Top And S.Top < Cells(x_end, 10).Top + Cells(x_end, 10).Height) And InStr(S.Name, "CommandButton") = 0 Then
            
                MyArray = Split(Join(MyArray, ",") & IIf(n = 0, "", ",") & S.Name, ",")
                
                n = n + 1
                
            End If

        Next S
    
    End With
    

    'Array("TextBox 4173", "TextBox 4164", "TextBox 4165", "TextBox 4174")
    ActiveSheet.Shapes.Range(MyArray).Select
    Selection.ShapeRange.Group.Select

End Sub

字符串
我该怎么做,谢谢。

nkkqxpd9

nkkqxpd91#

Shapes.Range接受数组作为参数,但它的索引必须从1开始。
因此,将此插入到代码中的End With语句之后。

ReDim c(1 To UBound(MyArray) + 1)
For i = 1 To UBound(MyArray) + 1
c(i) = MyArray(i - 1)
Next i

字符串
并更改参数

ActiveSheet.Shapes.Range(c).Select

相关问题