欢迎来到操纵您正在循环的收藏的美妙世界。
在你切割的那一刻,你实际上是从集合中移除了形状,改变了你的循环。
如果您想遍历形状(或表格行或其他)并从该集合中删除某些内容,只需向后退:
Dim i As Integer, oShp As Shape
For i = ActiveDocument.Shapes.Count To 1 Step -1
Set oShp = ActiveDocument.Shapes(i)
oShp.Select
Selection.Cut
Selection.PasteSpecial Link:=False, dataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
Next i
表的替代方案(警告:未经测试!)
Dim tbl As Table
For i = ActiveDocument.Tables.Count To 1 Step -1
Set tbl = ActiveDocument.Tables(i)
tbl.Select
Selection.Cut
Selection.PasteSpecial Link:=False, dataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
Next i
对于方程式:方程式是 InlineShapes 并且具有“OMath”属性。用它来识别方程对象。 警告:未经测试
Dim equation As InlineShape
For i = ActiveDocument.InlineShapes.Count To 1 Step -1
Set equation = ActiveDocument.InlineShapes(i)
If equation.OMath > 0 Then
equation.Select
Selection.Cut
Selection.PasteSpecial Link:=False, dataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
End If
Next i