错误400 - 对象的应用程序返回的错误 - Tableau(Range).Group

时间:2015-10-06 16:25:33

标签: excel vba excel-vba

我实际上遇到了以下代码的问题。

它浏览我的工作表的每个形状,一旦他检查了形状的类型,他就在数组Tableau()中添加了它的ID。

返回错误的行如下:

Set Sh = ActiveSheet.Shapes.Range(Tableau).group <== it might be a detail but VBA Editor doesn't change group by Group.

这是完整的代码:

Sub Select()

    Dim Sh As Object
    Dim Tableau()
    Dim i As Integer

    'Loop on the ActiveSheet Shapes
    For Each Sh In ActiveSheet.Shapes

        If Sh.Type <> msoFormControl Then
            i = i + 1
            ReDim Preserve Tableau(1 To i)
            Tableau(i) = Sh.ID
        End If
    Next Sh

    On Error GoTo Errorcatch

    'Group shapes whom the ID is in the array
    Set Sh = ActiveSheet.Shapes.Range(Tableau).group '<== Error 400

    'Rename the group
    Sh.name = "Group" & CStr(Rnd)

    Sh.Copy

Exit Sub

Errorcatch:
MsgBox Err.Description

End Sub

1 个答案:

答案 0 :(得分:0)

Sub SelectA()

Dim Sh As Object
Dim Tableau()
Dim i As Integer

'Loop on the ActiveSheet Shapes
For Each Sh In ActiveSheet.Shapes
    If Sh.Type <> msoFormControl Then

        ReDim Preserve Tableau(i)
        Tableau(i) = Sh.Name
        i = i + 1
    End If
Next Sh

On Error GoTo Errorcatch

'Group shapes whom the ID is in the array
Set Sh = ActiveSheet.Shapes.Range(Tableau).Group

'Rename the group
Sh.Name = "Group" & CStr(Rnd)

Sh.Copy

Exit Sub

Errorcatch:     MsgBox Err.Description

End Sub

由于