0

I have a text box within a footer in a Word doc. It has some template text that is left-aligned, and then already has the "Page x of n" right-aligned. When I try and replace the template text, all of the text is replaced.

Using C# or VB (either way) I need to replace the text inside of the text box (all of this text should be left-aligned) and then add "Page x of n" (right-aligned).

Here is what I have so far as a test:

string footer;

foreach (Shape shape in oMyDoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes)
{
  footer = shape.TextFrame.ContainingRange.Text;
  footer = footer.Replace("\r", "");
  footer = footer.Replace("[Quote Type]", "Big Quote");
  footer = footer.Replace("(", "\u2022");

  int start = footer.IndexOf("Pager ");

  footer = footer.Remove(start + 5);

  var numPages = oMyDoc.ComputeStatistics(WdStatistic.wdStatisticPages);

  footer = footer + " of " + numPages.ToString();

  shape.TextFrame.ContainingRange.Text = footer;
}
Jojo
  • 1,875
  • 3
  • 29
  • 29
Chris Boyd
  • 131
  • 1
  • 7
  • What does not work? Error? – Christian Sauer Feb 07 '14 at 09:24
  • As a suggestion: look if the Word-Footer has methods like "InsertPageNumber" like PowerPoint does. Then you don't have to reinvent the wheel. – Christian Sauer Feb 07 '14 at 09:25
  • @ChristianSauer It's not that I have code that doesn't work, it's that I can't figure out the code to get what I described. And no, there isn't a way to just plug in page numbers. The auto page number object is a Field object, and the closest I can get is replacing the entirety of the footer with that single object. – Chris Boyd Feb 07 '14 at 16:22

0 Answers0