none
Cannot seek primary header view through VBA, need alternative method to access it RRS feed

  • Question

  • msdn question

    I have exactly the same problem as in the linked question when doing the seek. By now it's obvious to me, that I am missing the second page to be able to navigate there.

    I still need to get there somehow, so I'm looking for a different approach. I am working inside a template document, and the template should not have a second page right from the start, but if the user inserts too much text for just one page, he will continue to the second and by then, the header needs to be preconfigured to show the same logo as the header on the first page, but with different text. I already set the document option to have a different first header, and I can configure it manually without problem.

    Can and if, how can I get to the (not yet created)  second page header using VBA?


    Currently I am doing this for the first header:


     wndDoc_g.ActivePane.View.SeekView = wdSeekFirstPageHeader
            wndDoc_g.Selection.MoveRight Unit:=wdCell, Count:=1
            Set objInlineShape = wndDoc_g.Selection.InlineShapes.AddPicture(Filename:=strBildname_g, LinkToFile:=False, SaveWithDocument:=True)
         
            With objInlineShape
                .LockAspectRatio = msoTrue
                sngBreite = PointsToCentimeters(.Width)
                sngHoehe = PointsToCentimeters(.Height)
                
             End With
    
        wndDoc_g.ActivePane.View.SeekView = wdSeekMainDocument


    Monday, December 3, 2012 12:47 PM

Answers

  • You don't need to use the Seek method to access any header or footer. For example:

    With wndDoc_g.Sections(1)
      ' Insert Picture into Cell A1 in the first-page header
      Set objInlineShape = .Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(1, 1).Range.InlineShapes.AddPicture _
      (FileName:=strBildname_g, LinkToFile:=False, SaveWithDocument:=True)
      With objInlineShape
        .LockAspectRatio = msoTrue
        sngBreite = PointsToCentimeters(.Width)
        sngHoehe = PointsToCentimeters(.Height)
      End With
      ' Insert Picture into the primary header
      Set objInlineShape = .Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture _
      (FileName:=strBildname_g, LinkToFile:=False, SaveWithDocument:=True)
    End With

    Of course, the above pre-supposes your document has a 'different first page' layout and that there is a table in the first-page header. No table is pre-supposed for the primary header. And, unlike the Seek method, you don't need a physical 2nd page to populate its header.


    Cheers
    Paul Edstein
    [MS MVP - Word]


    Monday, December 3, 2012 10:14 PM

All replies

  • You can't set the header or footer of a non-existent page, so...

    You'll have to insert a page break, go to the header of the second page, insert the logo and text, go back to the main document, and finally delete the page break again. Even though the second page doesn't exist any more, Word will remember its settings, so when the user enters enough text to create a second page, it will have the header you set.


    Regards, Hans Vogelaar

    Monday, December 3, 2012 1:03 PM
  • You don't need to use the Seek method to access any header or footer. For example:

    With wndDoc_g.Sections(1)
      ' Insert Picture into Cell A1 in the first-page header
      Set objInlineShape = .Headers(wdHeaderFooterFirstPage).Range.Tables(1).Cell(1, 1).Range.InlineShapes.AddPicture _
      (FileName:=strBildname_g, LinkToFile:=False, SaveWithDocument:=True)
      With objInlineShape
        .LockAspectRatio = msoTrue
        sngBreite = PointsToCentimeters(.Width)
        sngHoehe = PointsToCentimeters(.Height)
      End With
      ' Insert Picture into the primary header
      Set objInlineShape = .Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture _
      (FileName:=strBildname_g, LinkToFile:=False, SaveWithDocument:=True)
    End With

    Of course, the above pre-supposes your document has a 'different first page' layout and that there is a table in the first-page header. No table is pre-supposed for the primary header. And, unlike the Seek method, you don't need a physical 2nd page to populate its header.


    Cheers
    Paul Edstein
    [MS MVP - Word]


    Monday, December 3, 2012 10:14 PM