Word宏运行时错误' 70':权限被拒绝

时间:2015-03-30 09:21:09

标签: vba ms-word word-vba

我有一个宏删除图表,MS表格,Excel复制表格& MS Word中的图像

Sub deleteNoise()
    Dim i As Integer

    With ActiveDocument
        For i = .Tables.Count To 1 Step -1
            .Tables(i).Delete
        Next i
        ActiveDocument.Shapes.SelectAll
        Selection.Delete
    End With
End Sub

工作得很好。直到我保存文件并尝试运行它,现在它只删除表格,当它到达图像时,我收到以下错误。

  

运行时错误' 70':权限被拒绝

1 个答案:

答案 0 :(得分:1)

With声明是垃圾。

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