|
Sub CommandButton1_Click()
Dim x, y%, r, p, oDoc
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear
.Filters.Add "所有Word文件", "*.doc,*.docx", 1
.AllowMultiSelect = True
If .Show = -1 Then
For Each oFile In .SelectedItems
Set oDoc = Word.Documents.Open(FileName:=oFile, Visible:=False)
x = oDoc.ComputeStatistics(wdStatisticPages)
p = InputBox("请输入开始编码的起始页, 数字范围:1-" & x)
If p = "" Then y = 0 Else y = p
If y < 1 Or y > x Then
oDoc.Close SaveChanges:=False
Set oDoc = Nothing: Exit Sub
End If
oDoc.Activate
For Each fs In oDoc.Sections: fs.Footers(1).Range.Delete: Next
Selection.GoTo(wdGoToPage, wdGoToAbsolute, p). _
Bookmarks("\page").Range.InsertBreak wdSectionBreakNextPage
With oDoc.Sections(2).Footers(wdHeaderFooterPrimary)
.LinkToPrevious = False '不链接
.PageNumbers.RestartNumberingAtSection = True '不连续
.PageNumbers.StartingNumber = 1 '起始编号
Set r = .Range: r.Font.Name = "微软雅黑": r.Font.Size = 10
r.Text = "第 ": r.Collapse 0
oDoc.Fields.Add r, wdFieldPage, "Page"
Set r = .Range: r.Collapse 0
r.Text = " 页 / 共 ": r.Collapse 0
oDoc.Fields.Add r, wdFieldEmpty, "SectionPages"
Set r = .Range: r.Collapse 0: r.Text = " 页 "
.Range.Fields.Update
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
oDoc.Close SaveChanges:=True: Set oDoc = Nothing
Next
End If
End With
Application.ScreenUpdating = True
MsgBox "文档已处理!"
End Sub
|
评分
-
1
查看全部评分
-
|