none
Word 2003: Creating textbox in first page header results in primary header RRS feed

  • Question

  • Hello,

    I am trying to create a textbox in the first page header, in a Word 2003 document (file extension .doc) that has a different first page header (this behaviour also happens with different odd/even page headers). But instead, the textbox is created in the primary page header. This is the code I am using in my test app:

    float i = 0;
    foreach (WdHeaderFooterIndex index in Enum.GetValues(typeof(WdHeaderFooterIndex)))
    {
        var textbox = section.Headers[index].Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal,
                            10, 20 + i, 250, 20);
        textbox.TextFrame.TextRange.Text = index.ToString();
        i += 22;
    }

    The float i is to increment the top height so that the textboxes do not overlay each other.

    The same code works for .docx files, in that the textboxes are created on the correct pages. Any hints would be much appreciated.

    Thanks!

    Tuesday, April 12, 2016 8:08 PM

Answers

  • Hello Deepak,

    Thank you for your response, but I've figured out the issue. For anyone who comes across this in the future, the secret is to use seekview to "go into" the section first before creating a header, like so:

    Globals.MyAddin.Application.ActiveWindow.View.WdSeekView = WdSeekView.wdSeekEvenPagesHeader;
    // create your content that goes into the header here
    var textbox = Create_My_Textbox();
    Globals.MyAddin.Application.ActiveWindow.View.WdSeekView = WdSeekView.wdSeekMainDocument;

    The last line with wdSeekMainDocument is necessary to return to the main document to continue processing.

    Tuesday, April 19, 2016 1:57 PM

All replies

  • Hi PastryEater,

    First of all I would like to tell you that Microsoft has ended the support for Office 2003.

    please visit the link below.

    word 2003 support

    I think there is a something difference in the header of .doc and .docx and this causing this issue.

    you mention this thread in vsto forum i would like to know in which version of office you are using and what kind of app you are developing.

    is it necessary for you to use word 2003?

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 19, 2016 8:19 AM
    Moderator
  • Hello Deepak,

    Thank you for your response, but I've figured out the issue. For anyone who comes across this in the future, the secret is to use seekview to "go into" the section first before creating a header, like so:

    Globals.MyAddin.Application.ActiveWindow.View.WdSeekView = WdSeekView.wdSeekEvenPagesHeader;
    // create your content that goes into the header here
    var textbox = Create_My_Textbox();
    Globals.MyAddin.Application.ActiveWindow.View.WdSeekView = WdSeekView.wdSeekMainDocument;

    The last line with wdSeekMainDocument is necessary to return to the main document to continue processing.

    Tuesday, April 19, 2016 1:57 PM
  • Hi PastryEater,

    it good to know that you have found solution regarding your issue by yourself.

    Thank you for sharing the code and solution of your issue. so that if some one have the same issue like you can get solution too.

    Regards

    Deepak 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 20, 2016 7:38 AM
    Moderator