|
请楼主将要处理的文档放在一个文件夹中,压缩备份后,应用本宏(仅对提供的样稿“张三、李四”格式一样的 Word 文档有效!思路是:全部删除分页符,将文档保留第一节的页面设置):
********************
Sub 删除分页符_循环遍历文件夹()
On Error Resume Next
Dim fd As FileDialog, i As Long, doc As Document, p As String
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then p = fd.SelectedItems(1) Else Exit Sub
Set fd = Nothing
If MsgBox("确认要处理吗?(文件夹:" & p & ")", vbYesNo + vbExclamation, "LoopFolder") = vbNo Then Exit Sub
With Application.FileSearch
.LookIn = p
.SearchSubFolders = True
.FileName = "*.doc"
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
'***************************************************************************************处理单个文档
Set doc = Documents.Open(FileName:=.FoundFiles(i))
ActiveDocument.Content.Find.Execute findtext:="^b", replacewith:="", Replace:=wdReplaceAll
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = CentimetersToPoints(1.8)
.BottomMargin = CentimetersToPoints(1.8)
.LeftMargin = CentimetersToPoints(3.54)
.RightMargin = CentimetersToPoints(3.54)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1.5)
.FooterDistance = CentimetersToPoints(1.75)
.PageWidth = CentimetersToPoints(25.01)
.PageHeight = CentimetersToPoints(17.6)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionContinuous
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
.LayoutMode = wdLayoutModeLineGrid
End With
ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitFullPage
ActiveDocument.Close savechanges:=wdSaveChanges
'*******************************************************************************************************
Next i
MsgBox "处理完毕! 共处理 " & .FoundFiles.Count & " 个文件!", vbOKOnly + vbExclamation, "LoopFolder"
Else
MsgBox "There were no files found.", vbOKOnly + vbCritical, "LoopFolder"
End If
End With
End Sub |
|