Reply
 
Thread Tools Display Modes
  #1   Report Post  
winsomepal
 
Posts: n/a
Default Common changes for too many files

Hi
Can you please tell me how to delete header and footer of too many documents
at a time it the content in the footer is common to all the files
  #2   Report Post  
Greg Maxey
 
Posts: n/a
Default

Well if there are "too" many then it can't be done.

You can perform a find and replace in a batch of files in the same directory
with the following macro. If the footer text is the same in each file and
the text is unique to the footer you can define that text as the find string
and replace with nothing. If the text isn't unique to the footer then this
macro will need to be adapted to suit your needs:

Public Sub BatchFindReplaceAnywhere()

'Macro by Doug Robbins - 1st March 2004
'with additional input from Peter Hewett to replace text in all the
documents in a folder

Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim rngstory As Word.Range
Dim findText As String
Dim Replacement As String

' Get the folder containing the files
With Dialogs(wdDialogCopyFile)
If .Display 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With

'Close any documents that may be open
If Documents.Count 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If

FirstLoop = True

If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If

myFile = Dir$(PathToUse & "*.doc")

While myFile ""
'Get the text to be replaced and the replacement
If FirstLoop = True Then
findText = InputBox("Enter the text that you want to replace.", "Batch
Replace Anywhere")
If findText = "" Then
MsgBox "Cancelled by User"
Exit Sub
End If
Tryagain:
Replacement = InputBox("Enter the replacement text.", "Batch ReplaceAnywhere
")
If Replacement = "" Then
Response = MsgBox("Do you just want to delete the found text?",
vbYesNoCancel)
If Response = vbNo Then
GoTo Tryagain
ElseIf Response = vbCancel Then
MsgBox "Cancelled by User."
Exit Sub
End If
End If
FirstLoop = False
End If


'Open each file and make the replacement
Set myDoc = Documents.Open(PathToUse & myFile)
' Fix the skipped blank Header/Footer problem
MakeHFValid
' Iterate through all story types in the current document
For Each rngstory In ActiveDocument.StoryRanges
' Iterate through all linked stories
Do
SearchAndReplaceInStory rngstory, findText, Replacement
' Get next linked story (if any)
Set rngstory = rngstory.NextStoryRange
Loop Until rngstory Is Nothing
Next
'Close the file, saving the changes.
myDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub

Public Sub SearchAndReplaceInStory(ByVal rngstory As Word.Range, _
ByVal strSearch As String, _
ByVal strReplace As String)
'This routine supplied by Peter Hewett
Do Until (rngstory Is Nothing)
With rngstory.Find
..ClearFormatting
..Replacement.ClearFormatting
..Text = strSearch
..Replacement.Text = strReplace
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchAllWordForms = False
..MatchSoundsLike = False
..MatchWildcards = False
..Execute Replace:=wdReplaceAll
End With
Set rngstory = rngstory.NextStoryRange
Loop
End Sub
Public Sub MakeHFValid()
'And this too
Dim lngJunk As Long
' It does not matter whether we access the Headers or Footers property.
' The critical part is accessing the stories range object
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryT ype
End Sub

--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support
http://gregmaxey.mvps.org/word_tips.htm

winsomepal wrote:
Hi
Can you please tell me how to delete header and footer of too many
documents at a time it the content in the footer is common to all the
files



  #3   Report Post  
Suzanne S. Barnhill
 
Posts: n/a
Default

See http://www.gmayor.com/batch_replace.htm

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

"winsomepal" wrote in message
...
Hi
Can you please tell me how to delete header and footer of too many

documents
at a time it the content in the footer is common to all the files


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Files open as read only Danny Sanders Microsoft Word Help 2 March 8th 05 12:27 AM
Upgrading MS Office caused Word Docs to DISAPPEAR?! Friendship Center New Users 6 January 27th 05 10:56 PM
see copying files to cd january 11,2005 frank zangari New Users 2 January 13th 05 05:09 PM
Duplicate Files John Flatley New Users 1 December 22nd 04 09:17 AM
RECOVER Temp FILES from CD-RW Kimla Microsoft Word Help 0 December 6th 04 03:59 PM


All times are GMT +1. The time now is 03:43 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"