none
Text box in Different First Page 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. 

    I am trying the following code to add a text box in different first page footer. But its not working. It is inserting a footer in all other page but not in different first page.

    int DoesDocHasDifferentFirstPage = oWord.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter;
                            if (DoesDocHasDifferentFirstPage == -1)
                            {
                                //oWord.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = -1;
                                Microsoft.Office.Interop.Word.HeaderFooter footer = Globals.ThisAddIn.Application.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage];
                                Microsoft.Office.Interop.Word.Shape textBoxShape =
                                                footer.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
                                                footer.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage],
                                                footer.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage],
                                                200,
                                                20);
                                textBoxShape.TextFrame.TextRange.Text = "This is an inserted Text Box";
    }

    However, if I want to insert a free text by the following code, it works. But its not inserting the text box for above code. 

       int DoesDocHasDifferentFirstPage = oWord.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter;
                            if (DoesDocHasDifferentFirstPage == -1)
                            {
                                //oWord.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = -1;
                                //Microsoft.Office.Interop.Word.HeaderFooter footer = Globals.ThisAddIn.Application.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage];
                                //Microsoft.Office.Interop.Word.Shape textBoxShape =
                                //                footer.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
                                //                footer.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage],
                                //                footer.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage],
                                //                200,
                                //                20);
                                //textBoxShape.TextFrame.TextRange.Text = "This is an inserted Text Box";
    
                                Microsoft.Office.Interop.Word.Range footerRange = Globals.ThisAddIn.Application.ActiveDocument.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage].Range;
                                footerRange.InsertAfter("This is an inserted Free Text");
    }

    Monday, June 25, 2018 4:44 PM

All replies

  • Hello,

    >>But its not working. It is inserting a footer in all other page but not in different first page.

    In fact, it works for me. Check below demonstration.

    Will the issue only occurs on specific document or all the documents? Have you tried to create a new document for testing? 

    Have you tried to unload all the other add-ins for avoiding unknown effects? 

    Could you reproduce the issue on other PC? If yes, do you have any other code in your project? If not, I would suggest you try to repair your office.

    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.

    Tuesday, June 26, 2018 5:52 AM
  • Hi Terry,

    So it looks like the issue with that specific document. But for some reason, its putting the text box in header for different first page. Is there a different settings I have to use for different first page to add a text box in the footer ? I am suspecting its to do with the position of the text box. 

    Thanks for your help. 

    Monday, July 2, 2018 4:49 PM