|
本帖最后由 gbgbxgb 于 2022-3-4 19:31 编辑
发现使用网站提供的“粘贴代码”功能,粘贴代码后,有些字符缺失,现重新粘贴文本代码如下:
Sub my_DelPagesSaveAs()
Dim fs As Object, myPath$, thisDocumentName$, i&
Dim myDoc As Document, myDocName$, theSaveFormat&
'
Set fs = CreateObject("Scripting.FileSystemObject")
thisDocumentName = fs.getfilename(ThisDocument.FullName)
myPath = ThisDocument.Path
If Right(myPath, 1) <> "" Then myPath = myPath & "\"
'
myDocName = Dir(myPath & "*.doc", vbDirectory)
Do While myDocName <> ""
If (GetAttr(myPath & myDocName) And vbDirectory) = 0 Then
If myDocName <> thisDocumentName Then
Set myDoc = Documents.Open(myPath & myDocName)
With myDoc
i = .ActiveWindow.Panes(1).Pages.Count
If i > 1 Then
i = .ActiveWindow.Panes(1).Pages(i).Breaks(1).Range.Start
On Error Resume Next
.Range(0, i).Delete
If Err <> 0 Then
On Error GoTo 0
MsgBox "当前文档“" & myDocName & "”无法删除页!", vbExclamation, "错误"
DoEvents
.Close False
Else
On Error GoTo 0
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Delete
theSaveFormat = .SaveFormat
.SaveAs FileName:=myPath & myDocName, fileformat:=theSaveFormat
.Close False
End If
Else
.Close False
End If
End With
End If
End If
myDocName = Dir
Loop
The_Exit:
Set fs = Nothing
Set myDoc = Nothing
End Sub
|
|