none
Cannot seek primary header view through VBA RRS feed

  • Question

  • The call ThisDocument.ActiveWindow.View.SeekView = wdSeekPrimaryHeader failing for some documents producing run time exception 5895: Requested view is not available. The call should not fail. Could it be something specific to the document structure?

    Parul Gupta

    Thursday, August 30, 2012 7:57 AM

All replies

  • You have to be in Print Layout view to do this. Your post does not indicate what view you are using. Perhaps you should reconsider why you're using .SeekView when you can do whatever you need to by referencing the header directly. For example:
    ActiveDocument.Sections.First.Headers(wdHeaderFooterPrimary).Range.Text = "Hello"


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, August 30, 2012 8:05 AM
  • I am in print layout view only. And i have an application that uses this call to do some processing. Is the call failure specific to some document structuring?

    Parul Gupta

    Thursday, August 30, 2012 8:41 AM
  • I am in print layout view only.
    But are you sure the code isn't changing the view? If it's not, the error could be due to having, say, a dialogue box or object open. Either way, if you exit debug mode and switch to the document, you should be able to see what view it's in and what's active/selected.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, August 30, 2012 9:46 AM
  • The code is not changing the view. I simply tried the following:

    1. Open the word file (having a footer) in it (Print layout view).

    2. Running this single command through VBA Editor (Immediate window),

    Even this is not working. The command throws the exception "Requested View is not available."  (Also, there is no  dialog box or object open.)


    Parul Gupta

    Thursday, August 30, 2012 10:08 AM
  • Hi Parul

    ARe you able to go into the Header/Footer view as an end-user (via the RIbbon or double-click), starting from the same point you used when testing in the Immediate Window?

    Is the problem occurring only with the one document, or is it generally a problem?

    The thought I'm having is that the document may be damaged (corrupted), making impossible to access the header/footer information.


    Cindy Meister, VSTO/Word MVP

    Thursday, August 30, 2012 10:15 AM
    Moderator
  • Yes, I can do so via the ribbon and double click paths. The problem occurs only when i try doing this through VBA and that too when u try to seek either wdSeekPrimaryHeader or wdSeekPrimaryFooter. However, it works with wdSeekCurrentPageFooter etc. I have 2-3 documents with which i am facing the problem.


    Parul Gupta

    Thursday, August 30, 2012 10:41 AM
  • You might need to repair your Office installation (via Programs & Features > Microsoft Office > Change in the Windows Control Panel).

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, August 30, 2012 10:54 AM
  • Hi Parul

    <<when u try to seek either wdSeekPrimaryHeader or wdSeekPrimaryFooter. However, it works with wdSeekCurrentPageFooter etc. I have 2-3 documents with which i am facing the problem.>>

    Ah! Perhaps you have "Different First Page" or "Different Odd/Even" activated for these documents?

    Primary Header/Footer is the default, so if you've changed such a setting that might explain the behavior?


    Cindy Meister, VSTO/Word MVP

    Thursday, August 30, 2012 11:29 AM
    Moderator
  • Yes, "Different First Page" is activated, how does this makes a difference?

    With some other such documents, this call is working fine.


    Parul Gupta

    Thursday, August 30, 2012 11:48 AM
  • Ah! Perhaps you have "Different First Page" or "Different Odd/Even" activated for these documents?

    Primary Header/Footer is the default, so if you've changed such a setting that might explain the behavior?

    Hi Cindy,

    I tested for that early on - it makes no difference. Seeking the Primary header works fine regardless of what the page layout is or which page it's sought from.

    HOWEVER, if the document has a "Different First Page" and/or "Different Odd/Even" setup and a page displaying Primary header doesn't exist (eg only the first page has been created or the second/third page has been deleted), the command fails with the message Parul referred to.



    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, August 30, 2012 12:45 PM
  • Thanks Cindy and Paul for your valuable guidance.

    My document had a "Different First Page" setup and there was no second page. This was causing the problem.

    Thanks

    Parul


    Parul Gupta

    Friday, August 31, 2012 5:55 AM
  • Thank you for this great diagnostic, it helps me a lot !

    So, in office 2007:

    When a section in document has a "different first page" setup and no SECOND page, we MUST NOT use :

    .SeekView = Word.WdSeekView.wdSeekEvenPagesFooter

    And when a section in document has a "different first page" setup and no THIRD page, we MUST NOT use

    .SeekView = Word.WdSeekView.wdSeekPrimaryFooter

    My question is HOW do you test the number of pages os a section ? The following code is not working in office 2007:

    mySection.Range.Information(wdActiveEndPageNumber)

    What solution did you use to avoid the Seekview bug ?

    Thank you in advance (and sorry for my rusty english)

    Friday, May 30, 2014 6:48 AM
  • The simple answer is to not use it! You can access any header/footer without ever using the SeekView method. If you insist on using it, though, you can test the page count for the section beforehand, then decide what to do. For example:

    Dim StrMsg As String, i As Long
    With Selection.Sections.First
      With .Range.Characters
        i = .Last.Information(wdActiveEndPageNumber) - _
          .First.Information(wdActiveEndPageNumber) + 1
      End With
      StrMsg = "Section " & .Index & " page count: " & i
    End With
    MsgBox StrMsg


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, May 30, 2014 7:03 AM