Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Removing headers&footers (97 - 2000)

    Hi, I have a macro that removes the current header and footer of a document, but i was wondering how i can make this cycle through all headers and footers for the document. I imagine there is a method to ascertain how many headers/footers there are in the Active Document? I would use this number in a loop to cycle through and remove them all.

    I know that...

    ActiveDocument.Tables.Count

    gives the number of tables in the active documents

    Does anyone know if there is a similar method / property for headers / footers?
    Thanks,

    pmatz

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Removing headers&footers (97 - 2000)

    Have a look at the code that loops through each header and each footer in every section in <post#=119527>post 119527</post#>

    StuartR

  3. #3
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing headers&footers (97 - 2000)

    Thats great stuart - Thanks!

    i noticed that there is a 'Headersfooters' class, with a 'Count' method. This would be for something different it seems, as as your code shows, its the different sections i need to cycle through.

    cheers
    Thanks,

    pmatz

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Removing headers&footers (97 - 2000)

    If you look for the HeadersFooters collection in help then you will see that it says
    <hr>A collection of HeaderFooter objects that represent the headers or footers in the specified section of a document.<hr>
    StuartR

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

    Re: Removing headers&footers (97 - 2000)

    Each section in a document has up to three headers (first page, odd pages, even pages) and footers (idem). If you retrieve .Headers.Count or .Footers.Count for a section, you'll get 3 as result, whether these headers or footers actually exist or not. You can find out whether a specific header or footer exists by looking at its Exists property: ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Exists returns either True or False.

  6. #6
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Removing headers&footers (97 - 2000)

    Ok, *matz is slightly baffled!

    I used this code and it seems fine [img]/forums/images/smilies/smile.gif[/img]

    For Each secSection In ActiveDocument.Sections
    For Each hfHeader In secSection.Headers
    With hfHeader.Range
    .Delete
    .Style = ActiveDocument.Styles(wdStyleNormal)
    End With
    Next hfHeader
    For Each hfFooter In secSection.Footers
    With hfFooter.Range
    .Delete
    .Style = ActiveDocument.Styles(wdStyleNormal)
    End With
    Next hfFooter
    Next secSection

    thanks again
    Thanks,

    pmatz

Posting Permissions

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