[Visual Basic] 纯文本查看 复制代码
Sub DeleteLastPageOfDocs()
Dim fd As FileDialog
Dim aDoc As Document
Dim i As Long
Dim count As Long
Set fd = Application.FileDialog(FileDialogType:=msoFileDialogOpen)
With fd
.AllowMultiSelect = True
.Title = "请选择要处理的一个或多个 Word 文档"
.Filters.Add "Word 文档", "*.doc; *.docx", 1
If .Show = -1 Then
count = .SelectedItems.count
For Each vrtSelectedItem In .SelectedItems
Set aDoc = Documents.Open(vrtSelectedItem)
With ActiveDocument
.Bookmarks("\EndOfDoc").Range.Select
' 获取当前活动页面的页码
currentPageNumber = Selection.Information(wdActiveEndPageNumber)
' 遍历当前活动页面的内联形状对象并删除图片
For Each shape In ActiveDocument.Shapes
If shape.Anchor.Information(wdActiveEndPageNumber) = currentPageNumber Then
shape.Delete
End If
Next shape
For Each InlineShape In ActiveDocument.InlineShapes
If InlineShape.Range.Information(wdActiveEndPageNumber) = currentPageNumber Then
InlineShape.Delete
End If
Next InlineShape
End With
aDoc.Save
aDoc.Close
Next
MsgBox "已处理 " & count & " 个 Word 文档"
End If
End With
End Sub
没有设置读取路径,运行的时候弹窗多选你要操作的文件,点打开,会批量对其进行操作 |