![]() |
|
#1
|
|||
|
|||
|
Hi
I have a folder of Word 2010 documents and a lot of the documents have a 2 line footer, e.g. A list of employees is open for inspection at our offices. This company does not accept service by electronic mail or facsimile. This company is regulated by the Brewers Authority. This 2 line footer needs to be replaced with a 3 line footer, e.g. ABC Brewery is the trading name of ABC Brewery PLC, registered in England and Wales with company number ABC999. A list of employees is open for inspection at our offices. This company does not accept service by electronic mail or facsimile. This company is regulated by the Brewers Authority. Can anyone recommend a program or code that can deal with this amount of text (over a number of lines) in multiple document footers? Many thanks in advance. Kenneth |
|
#2
|
||||
|
||||
|
The following macro used as a custom process with
should do this. Try it on one of the documents first. The code will not process the footer if the change has already been made. Code:
Function NewFooter(oDoc As Document) As Boolean
Dim oSection As Section
Dim oFooter As HeaderFooter
Dim oRng As Range
Const strFind As String = "A list of employees is open for inspection at our offices."
Const strAddText As String = "ABC Brewery is the trading name of ABC Brewery PLC, registered in England and Wales with company number ABC999." & vbCr
On Error GoTo err_Handler
For Each oSection In oDoc.Sections
For Each oFooter In oSection.Footers
If oFooter.Exists Then
Set oRng = oFooter.Range
If InStr(1, oFooter.Range.Text, strAddText) = 0 Then
With oRng.Find
Do While .Execute(FindText:=strFind)
oRng.InsertBefore strAddText
Exit Do
Loop
End With
End If
End If
Next oFooter
Next oSection
NewFooter = True
lbl_Exit:
Exit Function
err_Handler:
NewFooter = 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 |
|
#3
|
|||
|
|||
|
Hi Graham
Many thanks for your response, it's greatly appreciated. You will have to forgive my ignorance but do I open a Word document, alt-11 and paste the code as it is, it doesn't appear as a macro? And how will it know which folder of documents it needs to process? As I say, forgive my ignorance. Kenneth |
|
#4
|
||||
|
||||
|
The macro is a function intended to be used as a custom process with the linked add-in, which handles the folders. You select the folder(s) from the add-in.
As for the code listing. This is installed in the normal template - see http://www.gmayor.com/installing_macro.htm You can then enter its name 'NewFooter' in the Custom Process dialog of the add-in. See my web page linked in the previous post for more details. You can use it with the current document; a folder full of documents; or a folder full of documents and all its sub folders. It works by examining all the footer ranges in the document(s) to check for the replacement text, and the original text. If the original text is present and the replacement text is not, then the replacement is added to the original as you requested.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find & Replace in Header/Footer in 1000 files
|
amodiammmuneerk@glenmarkp | Word | 12 | 03-05-2018 03:31 AM |
Created VBA to Find and Replace in Body, Header and Footer with Highlighting the replacement text
|
QA_Compliance_Advisor | Word VBA | 11 | 09-23-2014 04:40 AM |
How do I find/replace the same word in multiple documents?
|
Ineedhelp! | Word | 3 | 03-04-2014 03:50 PM |
Find & Replace in Header/Footer
|
PReinie | Word | 6 | 01-22-2014 06:45 PM |
| Footer Find & Replace Operation? | binar | Word | 1 | 02-05-2013 10:39 PM |