Link to home
Create AccountLog in
Microsoft Word

Microsoft Word

--

Questions

--

Followers

Top Experts

Avatar of JohnG316
JohnG316

Word Macro / Way to Remove All Headers and Footers
I have an application that generates RTF files, except that each page is setup as its own section with a header and footer.  I need to be able to create an overall header and footer that will include our company name and logo.

I am looking for a solution that will either remove all of the section/header/footer designations so i can create my own global header/footer
or
A way of creating a header/footer that will override the section ones.


Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of gilbargilbar

this should do it:
Sub RePaginate()
'macro by brian balster 20030821
'go to the beginging of the document and find first header
    Selection.HomeKey unit:=wdStory
    ActiveWindow.View.SeekView = wdSeekCurrentPageHeader
'loop through all pages on document
    Do
'find the next page's header and delete it
    Selection.WholeStory
    Selection.Delete
    If Selection.Information(wdActiveEndPageNumber) = _
        Selection.Information(wdNumberOfPagesInDocument) Then
        Exit Do
    Else
'goto next page's header
        ActiveWindow.View.NextHeaderFooter
    End If
    Loop While Selection.Information(wdActiveEndPageNumber) <= _
                Selection.Information(wdNumberOfPagesInDocument)
    'now do footers
     ActiveWindow.View.SeekView = wdSeekMainDocument
     
          Selection.HomeKey unit:=wdStory
    ActiveWindow.View.SeekView = wdSeekCurrentPageFooter
'loop through all pages on document
    Do
'find the next page's header and delete it
    Selection.WholeStory
    Selection.Delete
    If Selection.Information(wdActiveEndPageNumber) = _
        Selection.Information(wdNumberOfPagesInDocument) Then
        Exit Do
    Else
'goto next page's header
        ActiveWindow.View.NextHeaderFooter
    End If
    Loop While Selection.Information(wdActiveEndPageNumber) <= _
                Selection.Information(wdNumberOfPagesInDocument)
    'now we're done
    ActiveWindow.View.SeekView = wdSeekMainDocument
    MsgBox "Your document has had its headers and footers removed" & vbCr & _
           "Save to keep changes, don't save to don't :)"
End Sub

Avatar of JohnG316JohnG316

ASKER

Thanks.  i will test that out and get back to you.

Avatar of GrahamSkanGrahamSkan🇬🇧

I think it would be best to link all the headers and footers together.

You can do this manually with the 'Header and Footer'. View/Header and Footer and click on the 'Link to Previous' button.

Note that, depending on the settings for 'Header and footer' in the Page Setup for each section' you can have up to three different headers and footers for each section.

If you like, you can simply run this macro.

After that a change that you make in any section's header or footer will be reflected in all the others.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


The problem with linking the headers and footers together is that it would be a tedious process and these files number in the dozens with a lot of pages in each.

qilbar
When I run this macro, I get 2 errors.

Microsoft Visual Basic
Run-time error '28'; Out of Stack space

then, when I debug, it stops at the first occurrence of 'Selection.Delete'


I can send you one of the files if that will help

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of GrahamSkanGrahamSkan🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account
Microsoft Word

Microsoft Word

--

Questions

--

Followers

Top Experts

Microsoft Word is a commercial document editing program that is part of the Microsoft Office suite. It features numerous text-editing tools for creating richly formatted documents, along with tools for the use of macros in Word documents. Word's native file formats are denoted either by a .doc or .docx file extension. Plugins permitting the Windows versions of Word to read and write formats it does not natively support, such as the OpenDocument format (ODF) are available. Word can import and display images in common bitmap formats such as JPG and GIF. It can also be used to create and display simple line-art.