none
Annoying Problem With Editing Footers RRS feed

  • Question

  • Hi, I have below code, This code is intended to add some string to the left side of a footer and leave whatever string on right side unedited, The problem with this, the right side string is the page counter, and when I run this code, all pages right side text will be "Page 2 of 50" because I guess this code only changes the footer for page 2 which then applying the same text to all remaining pages, is there a way to do this, or a way to loop & Access each page's footer individually and manually set page number?? 

                foreach (Section wordSection in doc.Sections)
                {
                    Word.Range footerRange = wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
    
                    string FooterText = footerRange.Text;
                    footerRange.Text = "HI " + FooterText;
                }

    Tuesday, June 18, 2019 11:54 AM

All replies

  • Your use of:
    footerRange.Text = "HI " + FooterText
    converts everything in 'FooterText' to plain text. Try collapsing 'footerRange' before adding you new text, or using:
    footerRange.InsertBefore

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, June 18, 2019 11:03 PM
  • Your use of:
    footerRange.Text = "HI " + FooterText
    converts everything in 'FooterText' to plain text. Try collapsing 'footerRange' before adding you new text, or using:
    footerRange.InsertBefore

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Hey this is me (diff acc) Thanks for your Response, I added Footerrange.Collapse right before setting the footer text.. But the problem now is after i set the text, it's always on the right side, I have a Page number Inserted on footer, and after adding my new text, will be on the right alignment... It's a bit hard to explain... if you have some other place i would really like to show you image since i can't post images here :/ 

    Saturday, June 22, 2019 1:06 PM
  • And which direction did you tell Word to collapse to - Start or End?

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, June 22, 2019 10:04 PM