以下代码供参考: Sub Example() '从指定页的下一页开始计页码,如指定为10,则第11页为1. Dim wdDoc As Word.Document, wdRange As Word.Range Dim FieldRange As Word.Range, strField As String Dim myPages As Integer, CodesLenth As Integer Dim PageLenth As Integer, EndRange As Long Dim StartRange As Long myPages = 12 strField = "IF PAGE <= " & myPages & " " & """""" & " =PAGE-" & myPages CodesLenth = VBA.Len(strField) PageLenth = Len(CStr(myPages)) Set wdDoc = Word.ActiveDocument With wdDoc Set wdRange = .Sections(1).Headers(wdHeaderFooterPrimary).Range wdRange.Text = strField wdRange.SetRange 11 + PageLenth + 5, 11 + PageLenth + 5 + 4 .Fields.Add Range:=wdRange, Type:=wdFieldEmpty, PreserveFormatting:=False EndRange = wdRange.Paragraphs(1).Range.End - 1 wdRange.SetRange wdRange.Start - 1, EndRange .Fields.Add Range:=wdRange, Type:=wdFieldEmpty, PreserveFormatting:=False StartRange = wdRange.Paragraphs(1).Range.Start wdRange.SetRange StartRange + 3, StartRange + 7 .Fields.Add Range:=wdRange, Type:=wdFieldEmpty, PreserveFormatting:=False EndRange = wdRange.Paragraphs(1).Range.End - 1 wdRange.SetRange StartRange, EndRange .Fields.Add Range:=wdRange, Type:=wdFieldEmpty, PreserveFormatting:=False Set wdRange = .Sections(1).Headers(wdHeaderFooterPrimary).Range wdRange.Fields.Update End With End Sub 按说楼主既然在WORD中能做到,我觉得我可能写得多余了。 呵呵。 |