Solved

looking to remove header in multiple word docs

Posted on 2011-03-07
20
466 Views
Last Modified: 2012-05-11
Hi - we have about 600 word docs that have company logo as the header, that we need to remove. i was wondering if there was a somewhat easy way of doing this (ie not doing them one by one) Thought maybe there might be a magical batch file that could do this. Any help would be appreciated, even if someone could point me in the right direction.
0
Comment
Question by:hodgem
  • 7
  • 3
  • 2
  • +4
20 Comments
 
LVL 11

Expert Comment

by:Plantwiz
Comment Utility
Is your current header pointed at a file where it pulls the image from?  If so, replace that image with your new image.

However, I suspect that's not the case and will look and see if a scripting option may be available or if you are able to apply a new template to the .doc

Which version of WORD are you using?  2003, 2007 or 2010?  And which are most of these .doc created in?
0
 
LVL 11

Expert Comment

by:Plantwiz
Comment Utility
You may find this of use for your project:
http://www.shaunakelly.com/word/templates/attachtemplate.html

0
 
LVL 50

Expert Comment

by:teylyn
Comment Utility
@Plantwiz, templates won't help in this case. Templates carry the definition of styles etc. Templates may also include images, but these will only be included if you create a new document from a template. If you then attach a different template with a different image to the existing document, only the styles will affect the document. The image won't be changed out. The image is content. Content is not affected by attaching a different template.

If you want to remove images from document headers, you need to open the document, delete the image, save and close the document. This can be automated with a macro (which is outside of the scope of my expertise, though).

cheers, teylyn
0
 

Author Comment

by:hodgem
Comment Utility
Teylyn - sorry for the late response, but doesnt a macro only work within the document? I was hoping to find a way where i can have a folder that contains 300 docs, and run something that would remove the header from all documents within that folder. I know it may be impossible, but i figured there may be something ut there.
0
 
LVL 11

Expert Comment

by:Plantwiz
Comment Utility
@hodgem,

I haven't located anythign that will open each file and reapply a new template.

And teylyn is correct that changing the template alone doesn't automatically apply, my hope (and perhaps it wasn't conveyed in my previous post) was to find a scrip or such to apply a new template to each file, but it looks like a manual process.

Is there some reason that ALL the old files need to have the new logo?  Is this merely a housekeeping thing?  Or do each of these files get accessed frequently?  Simply curious.

For comparison, years back when eveything was paper, documents on old letterhead were simply acknowledge that they were created at a time prior to the new look (or new company name).  

Moving forward, perhaps it might make sense to keep all coorespondence on a page template without any letterhead and at the time it is printed, it could be pasted to an existing template wtih the correct letterhead?

Sorry, I just haven't come across anything that will 'update' old files without opening each one.
0
 

Author Comment

by:hodgem
Comment Utility
hi - thanks for response. We need to do this because we are a recruiting/staffing firm, and for the last 3 years when we get a resume from a potential employee, we add our header/logo/company info to the top of each resume, along with which recruiter in the company is working with that person. We now are going to be using an online service that will manage all of our resumes etc. When they go to imprt all of the resumes, there's some sort of process they use to go into the resumes (as a batch) and extract the person name who is associated with that resume. They told us that we need to remove the header, because their process will not give correct info with the header in place.
0
 
LVL 11

Expert Comment

by:Plantwiz
Comment Utility
hmmm....


I'll dig a little more.

I'm thinking for 600 files, I'd be leaning toward putting 2 or maybe 3 people on opening the old file, copy the contents (minus the header) and creating a new file, paste and save with no header.

I realize you are trying to avoid this.  It seems to me like a 2 maybe 3 day process at the most (so 2 people could possible be finished in 1 business day if they could work on it non-stop (breaks and lunch of course).


I'll look now...
0
 
LVL 11

Expert Comment

by:Plantwiz
Comment Utility
Still looknig...

Review this one:
http://www.oooforum.org/forum/viewtopic.phtml?t=72230
0
 
LVL 11

Expert Comment

by:Plantwiz
Comment Utility
And of course, you don't need a new .doc if you simply delete them...I anticipated you wanted to preserve the original (probably a bad presumption)
http://word.tips.net/Pages/T000259_Deleting_a_Header_or_Footer.html
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 11

Expert Comment

by:Plantwiz
Comment Utility
http://word.tips.net/Pages/T001777_Deleting_All_Headers_and_Footers.html

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

Again, you will need to enter each .doc to use rather than a batch for all 600 files.

It is recommended to make the above code into a toolbar button, so this will make the process much more efficient.   This one is far better than ones I saw previously.  Nevertheless, still requires going into the .doc.
0
 
LVL 31

Expert Comment

by:DrUltima
Comment Utility
This idea came up in the past.  I found this conversation on doing what you are seeking while traversing all files in a folder:

http://www.vbaexpress.com/forum/archive/index.php/t-12997.html

It failed to traverse sub-folders.  I am not a programmer, but perhaps the data there will help get there.  Even folder at a time is better than document at a time.

This link:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=45

Has example code to replace the header with something else and traverses a folder again, but not sub-folders.

Again, I know those are not solutions, but they may point you in the direction you are seeking...

DrUltima
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
use this code to process all the documents in a directory

Public Sub ProcessFolder(parmPath As String)
  Dim strFile As String
  Dim strPath As String
  Dim docThing As Document
  If Right$(parmPath, 1) = "\" Then
    strPath = parmPath
  Else
    strPath = parmPath & "\"
  End If
  strFile = Dir(strPath & "*.doc")
  Do Until Len(strFile) = 0
    Set docThing = Documents.Open(strPath & strFile)
    'process image in the header
    
    'save and close document
    docThing.Save
    docThing.Close
  Loop
End Sub

Open in new window

0
 
LVL 38

Expert Comment

by:Jim P.
Comment Utility
Can you upload an example doc? Even if its John Doe and you swap out the logo to the Northwind traders logo.

I have seen more than one way to have an image in a word doc.

But it should be relatively straightforward VBA code.

northwindlogo.jpg
0
 
LVL 80

Expert Comment

by:byundt
Comment Utility
The following code doesn't handle subfolders, but it does process every file within a folder. It deletes the original header and replaces it with the one from the document containing the macro. The code is based on the pieces posted by aikimark and Plantwiz, along with those changes needed to make each sub work in my Word 2010 test.

Were this Excel, I would have let the user pick the folder. It is Word, however, and I really don't know my way around the object model. So if somebody has a suggestion to make in that regard (as well as recursing through subfolders), both would be useful improvements.
Public Sub ProcessFolder()
  Dim strFile As String
  Dim strPath As String
  Dim docThing As Document
  Dim parmPath As String
  parmPath = "C:\VBA\Sample '11\WordTest\"    'Change this path to suit
  If Right$(parmPath, 1) = "\" Then
    strPath = parmPath
  Else
    strPath = parmPath & "\"
  End If
  strFile = Dir(strPath & "*.doc")
  Do Until Len(strFile) = 0
    Set docThing = Documents.Open(strPath & strFile)
    With docThing
        ReplaceHead docThing
        .Save
        .Close
    End With
    strFile = Dir
  Loop
End Sub

Sub ReplaceHead(docThing As Document)
    Dim oSec As Section
    Dim oHead As HeaderFooter
    Dim i As Long
    For Each oSec In docThing.Sections
        i = 0
        For Each oHead In oSec.Headers
            If oHead.Exists Then
                i = i + 1
                oHead.Range.Delete
                ThisDocument.Sections(1).Headers(i).Range.Copy    'Delete this line and next if you don't want any header
                oHead.Range.Paste
            End If
        Next oHead
    Next oSec
End Sub

Open in new window

Brad
0
 
LVL 38

Expert Comment

by:Jim P.
Comment Utility
byundt,

That will work fantastic if it is a true header. My concern is that it isn't a true header, but rather an image placed at the top of a doc.

I had to build a "macro" for WordPerfect back in the late 90's. Because sometimes the documents would have images in them sometimes not, I had go to the end of the document, place a "dummy" image and then go find any images and delete them, then re-add the logo only on the top of the first page.

But they weren't in a header. That is why I'm asking for an example.

Also I have done a combo of both yours and Mark's idea's. I would build an Access table of the directories, then feed the table into function one which fed into function two.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
@jimpen

Why build an Access table?
0
 
LVL 38

Expert Comment

by:Jim P.
Comment Utility
@akimark

I was processing the docs from an AccessDB.  I'm sure you could do the same thing off a Word doc. The point being that your routine takes a an external path -- so you would need a "wrapping" routine to get all the subdirectories processed.

byundt's routine has the path hard coded.
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
Comment Utility
I removed the hard-coded path and let the user pick any file in the folder that needs to be processed. I also commented out the two lines that were putting in a new header, since a closer reading of the question suggests that eradication is the desired result. If you download the sample document, you can run the macro from there--it is pre-installed.
Private Sub ToggleButton1_Click()
Dim parmPath As String, strFile As String, strPath As String
Dim docThing As Document, doc As Document
Dim i As Long
Set doc = ActiveDocument
MsgBox "A file browser will appear when you click OK. Please pick any file in the folder that needs to have its header removed."
Dialogs(wdDialogFileOpen).Show
If ActiveDocument Is doc Then
    MsgBox "No files were processed"
    Exit Sub
End If

Application.ScreenUpdating = False
Set docThing = ActiveDocument
parmPath = docThing.Path
If Right$(parmPath, 1) = "\" Then
    strPath = parmPath
Else
    strPath = parmPath & "\"
End If
docThing.Close savechanges:=False
  
strFile = Dir(strPath & "*.doc*")
Do Until Len(strFile) = 0
    i = i + 1
    Set docThing = Documents.Open(strPath & strFile)
    With docThing
        ReplaceHead docThing
        .Save
        .Close
    End With
    strFile = Dir
Loop
Application.ScreenUpdating = True
MsgBox i & " files were processed"
End Sub

Sub ReplaceHead(docThing As Document)
Dim oSec As Section
Dim oHead As HeaderFooter
Dim i As Long
For Each oSec In docThing.Sections
    i = 0
    For Each oHead In oSec.Headers
        If oHead.Exists Then
            i = i + 1
            oHead.Range.Delete
            'ThisDocument.Sections(1).Headers(i).Range.Copy      'Delete this statement and the next if you don't want to add a new header
            'oHead.Range.Paste
        End If
    Next oHead
Next oSec
End Sub

Open in new window

Brad
HeaderUpdater.doc
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now