我试过这个:
private void AddFooters()
{
foreach (Word.Section wordSection in this.WordDoc.Sections)
{
object fieldEmpty = Word.WdFieldType.wdFieldEmpty;
object autoText = "AUTOTEXT \"Page X of Y\" ";
object preserveFormatting = true;
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Add(
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range,
ref fieldEmpty, ref autoText, ref preserveFormatting);
}
}
和这个:
private void AddFooters()
{
foreach (Word.Section section in this.WordDoc.Sections)
{
Word.Range footerRange = section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
this.WordDoc.ActiveWindow.Selection.TypeText("Page ");
footerRange.Fields.Add(footerRange, Word.WdFieldType.wdFieldPage);
this.WordDoc.ActiveWindow.Selection.TypeText(" of ");
footerRange = section.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
footerRange.Fields.Add(footerRange, Word.WdFieldType.wdFieldNumPages);
footerRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
}
}
我录制了这个 VBA 宏,但它似乎没有帮助。
Sub Macro1()
'
' Macro1 Macro
'
'
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Bold Numbers 3"). _
Insert Where:=Selection.Range, RichText:=True
End Sub
我尝试过的任何事情都没有完全对我有用(我有点接近)。如果有关问题的某些内容不清楚,请告诉我。