none
Footer style changing entire footer RRS feed

  • Question

  • I am working on Office.Interop.Word using c#. I have a simple winform and has a button and all this button does,  place the name of the document at the footer. 

    If I use the following code, it changed the style for the existing footer (like page number or any other footer). How can I not changes the existing footer style and add the new footer as I want.

    //footerRange = wordSection.Footers[word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                            //footerRange.Font.ColorIndex = word.WdColorIndex.wdBlack;
                            //footerRange.Font.Size = 6;
                            //footerRange.Font.Name = "Arial";
                            //footerRange.InsertAfter(docNumber);


    Friday, June 22, 2018 2:54 AM

Answers

  • Hello,

    You could try to select the end of the footer range and then set font style for the selected range.

    Here is the simple code.

                string documentName = oDoc.Name;
                oWord.ScreenUpdating = false;
                Word.HeaderFooter footer = oDoc.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]; 
                oDoc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter;
                footer.Range.Select();
                oWord.Selection.MoveRight(Word.WdUnits.wdCharacter, 1);
                oWord.Selection.Font.ColorIndex = Word.WdColorIndex.wdRed;
                oWord.Selection.Font.Size = 6;
                oWord.Selection.Font.Name = "Arial";
                footer.Range.InsertAfter(documentName);
                oDoc.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
                oWord.ScreenUpdating = true;

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 22, 2018 9:08 AM