Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2019, 07:58 AM
rookieuk rookieuk is offline Removing headers from multiple files Windows 7 64bit Removing headers from multiple files Office 2010
Novice
Removing headers from multiple files
 
Join Date: Mar 2019
Posts: 2
rookieuk is on a distinguished road
Default Removing headers from multiple files


Hi,

I'm trying to remove headers from multiple (thousands) of documents.

I've been trying to use the code provided by macropod in this thread - https://www.msofficeforums.com/word-...html#post62942 but I'm not having any success.

The header I'm trying to remove is defined as 'Different first page' and I don't know if that makes any difference. (copy of example file attached hopefully).

Basically all I want to do is remove that header completely and not have to do it manually across a few thousand files! Please help!

Thanks
Rookie
Attached Files
File Type: doc Free Format.doc (32.0 KB, 9 views)
Reply With Quote
  #2  
Old 03-18-2019, 02:15 PM
macropod's Avatar
macropod macropod is offline Removing headers from multiple files Windows 7 64bit Removing headers from multiple files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

The code in that link is for replacing one header with another, using the document the macro is being run from as the source for the new headers. It is not written for deleting headers. Why are you trying to "remove headers from multiple (thousands) of documents"? In a commercial environment this could have serious adverse legal implications.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-19-2019, 02:01 AM
rookieuk rookieuk is offline Removing headers from multiple files Windows 7 64bit Removing headers from multiple files Office 2010
Novice
Removing headers from multiple files
 
Join Date: Mar 2019
Posts: 2
rookieuk is on a distinguished road
Default

Thanks for replying.

The headers shouldn't be there in the first place. Each document file is imported into a master template which has the relevant headers/footers already in it. These other documents should be 'clean'.

The exercise I'm undertaking is to update certain information and due to the mistake of these headers being in these sub-documents, the scope is wildly inaccurate.

If you can help me strip out the headers completely that would be great!

Thanks
Rookie
Reply With Quote
  #4  
Old 03-19-2019, 04:52 AM
gmayor's Avatar
gmayor gmayor is offline Removing headers from multiple files Windows 10 Removing headers from multiple files Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following function will selectively delete headers and footers from the document. You could use it with http://www.gmayor.com/document_batch_processes.htm as a custom process to handle the folders containing the documents. Try it on a single example before running it on many documents to ensure that it deletes what is required in your documents.

Code:
Function DeleteHeaders(oDoc As Document) As Boolean
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim oSection As Section
    On Error GoTo err_Handler

    For Each oSection In oDoc.Sections
        For Each oHeader In oSection.Headers
            If oHeader.Exists Then
                Select Case oHeader.Index
                    Case wdHeaderFooterFirstPage
                        'do nothing or oHeader.Range.Delete as required
                    Case wdHeaderFooterPrimary
                        oHeader.Range.Delete
                    Case wdHeaderFooterEvenPages
                        oHeader.Range.Delete
                End Select
            End If
        Next oHeader
        For Each oFooter In oSection.Footers
            If oFooter.Exists Then
                Select Case oFooter.Index
                    Case wdHeaderFooterFirstPage
                        'do nothing or oFooter.Range.Delete as required
                    Case wdHeaderFooterPrimary
                        oFooter.Range.Delete
                    Case wdHeaderFooterEvenPages
                        oFooter.Range.Delete
                End Select
            End If
        Next oFooter
    Next oSection
    DeleteHeaders = True
lbl_Exit:
    Set oSection = Nothing
    Set oHeader = Nothing
    Set oFooter = Nothing
    Exit Function
err_Handler:
    DeleteHeaders = False
    Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 03-19-2019, 02:46 PM
macropod's Avatar
macropod macropod is offline Removing headers from multiple files Windows 7 64bit Removing headers from multiple files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by rookieuk View Post
The headers shouldn't be there in the first place. …

If you can help me strip out the headers completely that would be great!
In that case, change both instances of:
Code:
                            If .LinkToPrevious = False Then
                                .Range.FormattedText = _
                                wdDocSrc.Sections.First.Headers(wdHeaderFooterPrimary).Range.FormattedText
                            End If
to:
Code:
                            If .LinkToPrevious = False Then .Range.Text = vbNullString
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2010 removing headers from pages with photos normancamp Word 6 03-31-2018 02:39 PM
Removing headers from multiple files Removing Hyperlinks in Multiple Documents at Once Jude24Joy Word VBA 10 06-13-2017 05:38 AM
Removing Sections from headers and footers Tonks811 Word 2 01-16-2016 10:30 PM
Updating headers in multiple files cellophane Word 3 01-17-2013 06:36 AM
Removing headers from multiple files convert multiple csv files to multiple excel files mit Excel 1 06-14-2011 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:01 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