|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 gbgbxgb 于 2022-3-4 18:14 编辑
- Sub my_DelPagesSaveAs()
- Dim fs As Object, myPath$, thisDocumentName$
- Dim myDoc As Document, myDocName$, theSaveFormat&, i&
- '
- 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
- 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
- Set fs = Nothing
- Set myDoc = Nothing
- End Sub
复制代码
|
|