Vba Microsoft Word宏删除除文本以外的所有内容
我试图在word中创建一个宏,删除除文本以外的所有内容 因此,图表/表格/excel表格/图像 我试着录下一个,并操纵它,但没有用 这适用于图像和图表,但不适用于表格/excel表格Vba Microsoft Word宏删除除文本以外的所有内容,vba,ms-word,Vba,Ms Word,我试图在word中创建一个宏,删除除文本以外的所有内容 因此,图表/表格/excel表格/图像 我试着录下一个,并操纵它,但没有用 这适用于图像和图表,但不适用于表格/excel表格 Sub deleteimages() Dim i As Integer With ActiveDocument For i = 1 To .InlineShapes.Count .InlineShapes(i).ConvertToShape
Sub deleteimages()
Dim i As Integer
With ActiveDocument
For i = 1 To .InlineShapes.Count
.InlineShapes(i).ConvertToShape
Next i
Dim Shp As Shape
For Each Shp In ActiveDocument.Shapes
If Shp.Type = msoTextBox Then Shp.Delete
Next Shp
For Each Shp In ActiveDocument.Shapes
If Shp.Type = msoTable Then Shp.Delete
Next Shp
ActiveDocument.Shapes.SelectAll
Selection.Delete
End With
End Sub
对于表,请使用以下命令:
Sub deletetables()
Dim i As Integer
With ActiveDocument
For i = .Tables.Count To 1 Step -1
.Tables(i).Delete
Next i
End With
End Sub
同样的逻辑用于图表和其他对象
有关更多信息,请参阅:
顺便说一下:我建议从最后一个开始删除对象,因为有很多原因。另一种方法是使用Do While。。。循环
:
Do While ActiveDocument.Tables.Count>1
ActiveDocument.Tables(1).Delete
Loop
此宏删除图表、MS表格、Excel复制的表格和图像
Sub deleteNoise()
Dim objPic As InlineShape
For Each objPic In ActiveDocument.InlineShapes
objPic.Delete
Next objPic
Dim tbl As Table
For Each tbl In ActiveDocument.Tables
tbl.Delete
Next tbl
Dim shp As Shape
ActiveDocument.Shapes.SelectAll
Selection.Delete
End Sub
MS Word有几个内置的集合。使用它们来删除不需要的项目。最终得到了一个权限错误,所以我重新创建了我的(回答如下)