With this code
HeaderFooter _footer = sections[3].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary];
_footer.PageNumbers.RestartNumberingAtSection = true;
_footer.PageNumbers.StartingNumber = 1;
object CurrentPage = WdFieldType.wdFieldPage;
object TotalPages = WdFieldType.wdFieldSectionPages;
Range footerRange = _footer.Range;
footerRange.Text = "Line1\t";
footerRange.Collapse(WdCollapseDirection.wdCollapseEnd);
footerRange.Fields.Add(footerRange, ref CurrentPage, Nothing, true);
footerRange.InsertAfter(" / ");
footerRange.Collapse(WdCollapseDirection.wdCollapseEnd);
footerRange.Fields.Add(footerRange, ref TotalPages, Nothing, true);
footerRange.InsertParagraph();
footerRange.InsertAfter("Line2");
I cannot post pictures now. So I post the pictures URLs here.
https://i.stack.imgur.com/6uwXQ.png
https://i.stack.imgur.com/BH982.png
Please notify that the current page num “1” and the section pages number “2” appear at the end of the footer.
I have tried the following two macro codes. They all work very well.
Selection.TypeText Text:="line1" & vbTab
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _"PAGE ", PreserveFormatting:=True
Selection.TypeText Text:="/"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _"SECTIONPAGES ", PreserveFormatting:=True
Selection.TypeParagraph
Selection.TypeText Text:="line2"
Selection.TypeText Text:="line1" & vbTab
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage, Text:= _"", PreserveFormatting:=True
Selection.TypeText Text:=" / "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldSectionPages, Text:= _"", PreserveFormatting:=True
Selection.TypeParagraph
Selection.TypeText Text:="line2"
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.