|
楼主,请试试下面的代码(仅对2003版有效):
- Sub aaaa循环遍历文件夹_插页码边距()
- On Error Resume Next
- Dim fd As FileDialog, i&, doc As Document, p$
- MsgBox "请双击进入文件夹,直到进入最终要处理的文件夹,确定即可!", vbOKOnly + vbExclamation
- Set fd = Application.FileDialog(msoFileDialogFolderPicker)
- If fd.Show = -1 Then p = fd.SelectedItems(1) Else Exit Sub
- Set fd = Nothing
- If MsgBox("是否处理文件夹 " & p & " ?", 4 + 48) = vbNo Then Exit Sub
- With Application.FileSearch
- .NewSearch
- .LookIn = p
- .SearchSubFolders = True
- .FileName = "*.doc"
- If .Execute > 0 Then
- For i = 1 To .FoundFiles.Count
- Set doc = Documents.Open(FileName:=.FoundFiles(i)) '打开文档
- 插页码边距 '引用宏名/设置文档格式
- doc.Close savechanges:=wdSaveChanges '保存退出
- Next i
- MsgBox "处理完毕!共处理 " & .FoundFiles.Count & " 个文件!", 0 + 48
- Else
- MsgBox "未发现文件!", 0 + 16
- End If
- End With
- End Sub
- Sub 插页码边距()
- On Error Resume Next
- With ActiveDocument.PageSetup
- .LineNumbering.Active = False
- .Orientation = wdOrientPortrait
- .TopMargin = CentimetersToPoints(1)
- .BottomMargin = CentimetersToPoints(1)
- .LeftMargin = CentimetersToPoints(1)
- .RightMargin = CentimetersToPoints(1)
- .Gutter = CentimetersToPoints(0)
- .HeaderDistance = CentimetersToPoints(1.5)
- .FooterDistance = CentimetersToPoints(1.5)
- .PageWidth = CentimetersToPoints(21)
- .PageHeight = CentimetersToPoints(29.7)
- .FirstPageTray = wdPrinterDefaultBin
- .OtherPagesTray = wdPrinterDefaultBin
- .SectionStart = wdSectionNewPage
- .OddAndEvenPagesHeaderFooter = False
- .DifferentFirstPageHeaderFooter = False
- .VerticalAlignment = wdAlignVerticalTop
- .SuppressEndnotes = False
- .MirrorMargins = False
- .TwoPagesOnOne = False
- .BookFoldPrinting = False
- .BookFoldRevPrinting = False
- .BookFoldPrintingSheets = 1
- .GutterPos = wdGutterPosLeft
- .LayoutMode = wdLayoutModeLineGrid
- End With
- Selection.WholeStory
- Selection.ParagraphFormat.Space1
- ActiveDocument.StoryRanges(wdPrimaryFooterStory).Frames(1).Cut '删除页码
- ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter '插入页码
- Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
- NormalTemplate.AutoTextEntries("第 X 页 共 Y 页").Insert Where:=Selection.Range, RichText:=True
- ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
- End Sub
复制代码 |
|