Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    York, Pennsylvania, USA
    Posts
    164
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Word header content (Word XP SP1)

    I have a number of boilerplate documents where I'm going to update the header (graphic or graphic w/text). Some number of these documents do not have a header, so they do not have to be updated.

    I'd rather not build in a list of documents, by name, which don't have anything in the header.

    Is there a way to tell if a header contains text or graphics? Or if it is empty?

    TIA

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word header content (Word XP SP1)

    The HeaderFooter object has a property Exists. The following example is from the Word 2002 VBA online help:

    Dim secTemp As Section

    Set secTemp = ActiveDocument.Sections(1)
    If secTemp.Headers(wdHeaderFooterFirstPage).Exists = True Then
    secTemp.Headers(wdHeaderFooterFirstPage).Range.Tex t = "First Page"
    End If

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Word header content (Word XP SP1)

    Hans has provided some code to get you started but there is one gotcha that I will mention in case it applies to you. This is only relevant to multi-section documents which contain floating objects in the headers or footers.

    Floating objects in the headers/footers do not appear to be listed in the section that they apply to. If you are using floating objects in your headers then using VBA to decide if a section has an empty header can be problematic.

    If this applies to you, let me know and I can provide more information if you require it.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    York, Pennsylvania, USA
    Posts
    164
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Re: Word header content (Word XP SP1)

    Thanks, Hans and Andrew. I missed that method, darn it. I'll play with the code today and see if I can make my routine generic.

    Andrew, Appreciate the heads up and I'll see if I need to expand the code for that. I've got about 800 boilerplate documents to certify :>)

  5. #5
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    York, Pennsylvania, USA
    Posts
    164
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Re: Word header content (Word XP SP1)

    I got close, folks.

    There's a bug with Word 2002. If you've ever had a header, then delete it, it leaves a paragraph mark behind. The code then thinks there's a header.

    MS Knowledgebase has a document on it. You have to get a replacement winword.exe from them to fix it, and be on SP2.

    We're on SP1 and I kind of got a hunch our systems folks won't be upgrading 500 PC's with SP2, followed by a patch.

    Bummer.

  6. #6
    New Lounger
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word header content (Word XP SP1)

    As far as I can tell this will identify if there is any content, other than just the paragraph mark. I tested with text, with graphics, with field codes, with embedded objects and it seems to work. The paragraph mark in the header is not a bug. Headers are their own "story", and just like the main story, there is always at least ONE paragraph mark.

    Sub EmptyHead()
    Dim aDoc As Document
    Dim char
    Set aDoc = ActiveDocument
    With aDoc.ActiveWindow.View
    .Type = wdPrintView
    .SeekView = wdSeekCurrentPageHeader
    End With

    With Selection
    .Collapse
    .Expand Unit:=wdEvenPagesHeaderStory
    End With
    char = Selection.EndOf(Unit:=wdParagraph, Extend:=wdMove)
    If char = 0 Then
    MsgBox "Nothing but paragraph mark." ' in the case mentioned, probably exit sub?
    Else
    MsgBox "something is here" ' do something else
    End If
    ' returns to main doc
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Set aDoc = Nothing
    End Sub

  7. #7
    New Lounger
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word header content (Word XP SP1)

    Well I have to say that is a bit more simple and elegant than my code. I also must mention that when ever I create a new document, there is always a paragraph mark in the header. Always. I do nothing except create a new doc, then go View, HeaderFooter, and by golly there is a paragraph mark. I think they may have the knowledge base description as a bug because - I don't know - the concept of separate "stories" is strange. To me though, it is exactly like trying to delete the paragraph mark in an empty document. You can't. End of story...that is a joke.

  8. #8
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    York, Pennsylvania, USA
    Posts
    164
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Re: Word header content (Word XP SP1)

    (Edited by HansV to create link to MSKB article using <!t>[MSKB=...]<!/t> tag)

    Hi Gerry,

    I threw something together that also seems to work (sorry if this formats ugly):

    If secTemp.Headers(wdHeaderFooterFirstPage).Exists = True Then
    iTemp = secTemp.Headers(wdHeaderFooterFirstPage).Range.Sto ryLength
    If iTemp > 1 Then
    'Then there's something in the header besides a paragraph marker

    <!mskb=813816>Microsoft Knowledge Base Article 813816<!/mskb> describes the problem I had - it's titled 'Paragraph Mark in the Header Remains After You Delete the Text in the Header' for WD2002

    If you create a new document, you'll see that there's nothing in the header.

    If you insert something in the header, save it, then whack what's in the header, you'll see a pesky paragraph mark remains, so it fails the first line of the code above.

    Since the headers I'm looking at have a graphic in them (at least the 'valid' ones), I'll get a count of 2. A count of 1 indicates just a paragraph mark and I can skip that document.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word header content (Word XP SP1)

    Hi Gerry,

    If you always have a paragraph marker (and only that) in the header in a new document, that must have crept into your Normal.dot, because that is what a blank new document is based on. You might experiment by opening Normal.dot directly, and editing the header - put some text into it, then close the header, edit it again, select everything (Ctrl+A) and delete it.

  10. #10
    New Lounger
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word header content (Word XP SP1)

    Yes I know normal.dot is the basis of New. So, here goes. I did everything you suggested. When a new document is created, there is NO paragraph mark visible in the header. Yet if you go into view the header, there is the paragraph mark. Exit header view, can't see the mark. Go back into header view and put some text in. Exit - yup can see the text and mark. Back into Header view and delete everything via Ctrl-A. It nows looks exactly like it does in a brand new document. Except...now the mark shows when I exit Header view.

    I deleted normal.dot (after appropriate back up), thus generating a new normal.dot with standard defaults.

    It behaves precisely the same way. There is a paragraph mark in the header. It is not visible (outside of Header view), but if text is inserted and removed, then the mark DOES show outside of Header view. I read the KB article and I am quite curious to know what the hotfix actually does. To me, it makes sense that there would be a mark. It is the Header Story, and like the main story there has to be an end..even if the middle (the content) is blank.

    BTW: I just checked 8 other machines (each running Word locally), and every one makes a paragraph mark in the header of a blank document. Word 2002 SP-1.

    Most interesting. Are you saying that you do not get a paragraph mark in the header of a blank doc?


    Regards,

  11. #11
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: Word header content (Word XP SP1)

    Hi Gerry,

    I have Office 2002 with SP-2 applied. I recently noticed the empty header in my normal.dot and did the following:

    First, in a document based on Normal, if I clicked View | Header and Footer, then closed the empty header, the header no longer displayed.

    Next, I opened normal.dot, and did the same thing -- opened and closed the header. The header no longer displayed. I saved normal and now I no longer start with a blank header.

    However, I walked through the steps you outlined and was unable to reproduce your results -- the emptied header does not appear -- so it may be this was fixed in SP-2?

    Unfortunately, I can't say when the empty header appeared -- before or after SP-2 was applied -- I just know one day I started wondering about it. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    Kim

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word header content (Word XP SP1)

    Gerry,

    Just like Kim Murdock, I have Word 2002 SP-2, and for me, it's like this:
    - A new document doesn't show a paragraph mark in the header in Print Layout view (it is visible in Header/Footer view)
    - If I enter something in the header, this text plus the paragraph mark is visible (grayed out) in Print Layout view.
    - If I select all header text and delete it, then return to Print Layout view, there is no paragraph mark visible in the header.

    But the MSKB article states that the hotfix available for your problem is a post SP-2 fix, so apparently installing SP-2 does not solve the problem on all systems. Still, I would suggest that you install SP-2 and see if that takes care of it. If not, you can request the hotfix from Microsoft - it requires SP-2 to be installed anyway. Or, of course, you can decide to live with the problem, it is not really serious - but that's for you to decide.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •