Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-10-2022, 04:57 PM
KATSLaw2023 KATSLaw2023 is offline New to Macros: Cannot remove Header/Footer: MS Word Windows 10 New to Macros: Cannot remove Header/Footer: MS Word Office 2016
Novice
New to Macros: Cannot remove Header/Footer: MS Word
 
Join Date: Sep 2022
Location: Newark, Ohio USA
Posts: 1
KATSLaw2023 is on a distinguished road
Default New to Macros: Cannot remove Header/Footer: MS Word

I have managed not to need how to use macros all of these years, until finding out that I have this magical header which is only magical because I've done everything that I know to remove it and it remains, now I have other issues because I have been playing with the developer settings. Another element to MS Word that I have never known about (all these years!).

I used the remove macro found online on a YouTube video, however the steps that was shown were not exactly the steps I used, because something didn't work out as I entered the macro script to visual basic, then I guess I was supposed to exit and return to the Word document, then to click on the macro-option and click run. Nothing happens when I do this.

Macro Code:
Code:
Sub RemoveHeadAndFoot()
    Dim oSec As Section
    Dim oHead As HeaderFooter
    Dim oFoot As HeaderFooter
    For Each oSec In ActiveDocument.Sections
        For Each oHead In oSec.Headers
            If oHead.Exists Then oHead.Range.Delete
        Next oHead
        For Each oFoot In oSec.Footers
            If oFoot.Exists Then oFoot.Range.Delete
        Next oFoot
    Next oSec
End Sub

The book is 900 pages, and in order to get the formatting correct for digital printing and paper back, I really need to remove the headers and footer so I can get the pages the way they are supposed to be in the published format.

All help is greatly appreciated!

Thank you so much!!
Reply With Quote
  #2  
Old 09-10-2022, 08:43 PM
BrianHoard BrianHoard is offline New to Macros: Cannot remove Header/Footer: MS Word Windows 10 New to Macros: Cannot remove Header/Footer: MS Word Office 2019
Advanced Beginner
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Sounds to me like you may simply be entering your code in the wrong place. Hard to tell by your question. But I just did a quick test with your code and it worked on a small 2 page document, so it may work for you.
To use your script, try these steps...
  1. Open a copy of your 900 page document (working with a backup in case something goes wrong.)
  2. As an initial test, I'd delete 880 pages, so you have something easy to work with as you test this out.
  3. Press Alt F11 to open the Visual Basic editor.
  4. Right-click on your document in the Project area (screen shot attached), and select Insert Module
  5. Double-click on the module and paste in your code in the VBA code area.
  6. If all looks good, no red text, press F5 or press the play button to run your code.
If you get an error or anything doesn't work, please post the exact error you receive.
Attached Images
File Type: png wordSnap.png (219.8 KB, 12 views)
Reply With Quote
  #3  
Old 09-11-2022, 03:22 PM
macropod's Avatar
macropod macropod is offline New to Macros: Cannot remove Header/Footer: MS Word Windows 10 New to Macros: Cannot remove Header/Footer: MS Word Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

All you should need is:
Code:
Sub RemoveHeadAndFoot()
Application.ScreenUpdating = False
Dim Sctn As Section, HdFt As HeaderFooter
For Each Sctn In ActiveDocument.Sections
  For Each HdFt In Sctn.Headers
    With HdFt
      If .Exists = True Then .Range.Text = vbNullString
    End With
  Next
  For Each HdFt In Sctn.Footers
    With HdFt
      If .Exists = True Then .Range.Text = vbNullString
    End With
  Next
Next
End Sub
For PC macro installation & usage instructions, see: Installing Macros
For Mac macro installation & usage instructions, see: Word:mac - Install a Macro
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
footer, header, macro word



Similar Threads
Thread Thread Starter Forum Replies Last Post
New to Macros: Cannot remove Header/Footer: MS Word how to remove 'header' 'footer' labels? abrogard Word 2 05-15-2022 06:50 PM
Adding text to the header and footer without removing all other content in the header and footer digitalelise Word VBA 2 10-23-2019 02:58 AM
Add, Resize & Relocate Header & Footer with Macros Sarah123 Word VBA 11 11-13-2018 07:15 AM
New to Macros: Cannot remove Header/Footer: MS Word Can't remove header & footer formatting ... frangipan Word 2 07-11-2014 12:27 PM
How do I remove header and footer captn1 Word 2 09-04-2010 04:14 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:15 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft