lizziegirl
New Member
- Joined
- Apr 3, 2006
- Messages
- 31
Hi all
I am struggling to do the above. I need to change a small piece of text in the footer in multiple documents in a fairly big directory. Some may be docs, dots, dotm, docx....etc
Some may be protected, some may not.
I have the below but something is not kicking off.
Do I store this in ThisDocument in a normal.dot?
And where do I place the normal dot?
Sorry for the naivety...
Thanks in advance..
LG
I am struggling to do the above. I need to change a small piece of text in the footer in multiple documents in a fairly big directory. Some may be docs, dots, dotm, docx....etc
Some may be protected, some may not.
I have the below but something is not kicking off.
Do I store this in ThisDocument in a normal.dot?
And where do I place the normal dot?
Sorry for the naivety...
Thanks in advance..
LG
Code:
Public Sub MassReplace()
Dim Directory As String
Dim FType As String
Dim FName As String
Directory = "T:\Testing"
FType = "*.dot"
ChDir Directory
FName = Dir(FType)
' for each file you find, run this loop
Do While FName <> ""
' open the file
Documents.Open FileName:=FName
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
' search and replace the text
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Looking for this text"
.MatchCase = True
.Replacement.Text = "replacing with this text"
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
' save and close the current document
ActiveDocument.Close wdSaveChanges
' look for next matching file
FName = Dir
Loop
End Sub