更新时间:2022-06-14 21:21:51
也许符合以下情况:
With Workbooks("target workbook name")
For i = 1 To .Connections.Count
.Connections(1).Delete
Next
End With
在您的情况下,您似乎需要将与ActiveWorkbook一起使用
。请注意,删除索引 i
最终会出错,因为删除操作更改了正在迭代的集合: i
将最终大于集合的大小。
In your case, it looks like you'd need to use With ActiveWorkbook
. Note that deleting index i
would eventually run into an error, since the deletion is altering the collection being iterated: i
would eventually be larger than the collection size.
或者:
With Workbooks("target workbook name")
Do While .Connections.Count > 0
.Connections(1).Delete
Loop
End With