|
Sub 批量插入不同的页眉页脚()
Dim oDoc As Document
Set oDoc = Word.ActiveDocument
Dim oSec As Section, t As String
With oDoc
On Error Resume Next
For i = 1 To .Sections.Count
With .Sections(i)
sr = Replace(Left(.Range.Text, Len(.Range.Text) - 2), Chr(12), "")
If InStr(sr, "[") > 0 Then
k = 1: t = sr
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.Headers(wdHeaderFooterPrimary).Range.Text = sr
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
.Footers(wdHeaderFooterPrimary).Range.Text = sr & "第1页"
Else
k = k + 1
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
.Footers(wdHeaderFooterPrimary).Range.Text = t & "第" & k & "页"
End If
End With
Next
End With
End Sub |
|