• Inserting a textbox in a header.

    Author
    Topic
    #353290

    I am trying to set up a portrait header for a landscaped page in a document. Below is the code I am currently trying to insert a text box for the text:

    On Error GoTo NoLandEvenHeader
    ActiveWindow.ActivePane.View. _
    SeekView = wdSeekEvenPagesHeader
    Set myTextBox = varSection. _
    Headers(wdHeaderFooterEvenPages).Shapes.AddTextbox _
    (wdTextOrientationDownward, _
    InchesToPoints(10), _
    InchesToPoints(0.75), _
    InchesToPoints(0.5), _
    InchesToPoints(6.5))
    myTextBox.Select
    Selection.EndKey Unit:=wdLine, Extend:=wdMove
    NoLandEvenHeader:

    When the SeekView routine is called, if the section has only one page, then even or primary pages will fail with the Runtime Error 5895, “Requested View is Not Available.”

    I understand why the view is not available, but the error trapping doesn’t catch it so that I can skip that header.

    Of course I’d prefer a routine that would insert the text box for all 3 headers of a section, just in case the landscaped page changes from odd to even because of other pages inserted.

    Thanks,
    mike c.

    Viewing 3 reply threads
    Author
    Replies
    • #516404

      One way to get around it would be to insert two page breaks into the section before hitting the header view area. When done you can delete them again.

      The other option would be to use ranges instead of selection objects.

    • #516409

      You might be able to “cheat” using the old WordBasic object. I have this in some code to set the header (not the first page header):

      ActiveWindow.View.Type = wdNormalView
      WordBasic.NormalViewHeaderArea
      With Selection
      ‘do stuff
      End With
      WordBasic.ClosePane

      You have no control over what you get in this pane, but from my limited testing:

      (1) First page different; no odd/even: opens p2 header;
      (2) Odd/even; no first page different: opens even header;
      (3) Both: opens first page header.

      You can check the header settings for a given section in the PageSetup object

    • #640624

      Please look at this thread for an elegant solution

    • #640636

      I don’t know if this applies in this situation, but I’ve often found that errors on trying to deal with viewing headers/footers can be stopped by adding ‘activedocument.’ to the front of the ‘activewindow.activepane.view …’ lines.

      I don’t know why it works but it has done so in the past!

    Viewing 3 reply threads
    Reply To: Inserting a textbox in a header.

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: