none
problem with wdseekcurrentheader not getting the current page header RRS feed

  • Question

  • Hi,

    I have written a vb.net app that creates a word 2007 document.  In this doc, I am putting info in the header field.  To do this, I use the wdseekcurrentheader command to get into the header of the page I am currently on.  Sometimes, when that command is excuted, word will take me back a few pages and select that header.  The odd this is when i am in the main doc, the number of pages differs from the number of pages when I set the current view to the header.  For example, i have a doc that when i open it and go to the end of the doc, the doc thinks i am on page 40 of 40 pages.  I then select the header, and suddenly, word thinks i am on page 40 or 47 pages.  Has anyone ever encountered this before, and, does anyone know how to fix it?

    Thanks!


    Inga Allred
    Monday, February 7, 2011 2:35 PM

Answers

  • Hi Inga

    the "Seek" part of the object model has always been unreliable for working with header/footer objects. It's much better to work directly with the corresponding Range object and not try to imitate the user selection behavior. For example:

    Dim rng as Word.Range = doc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
    rng.Text = "some text"

    The other part of your problem description - the changing page count - makes me think the file might also be corrupted...


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Monday, February 14, 2011 10:01 AM
    Monday, February 7, 2011 4:50 PM
    Moderator