Microsoft Office Tutorials and References
In Depth Information
Finding and Replacing in Multiple Documents
ProcessDoc doc, linkPath¶
'If changes were made, document was saved¶
'before, so don't save again¶
doc.Close SaveChanges:=wdDoNotSaveChanges¶
Set doc = Nothing¶
End If¶
Next fil¶
'folder not found. Unlikely, since was picked¶
'from folder dialog.¶
End If¶
Set fso = Nothing¶
End Sub¶
' * * * * *¶
Sub ProcessDoc(ByRef doc As Word.Document, linkPath As String)¶
'Variable declaration¶
Dim rng As Word.Range¶
'Loop through all parts of a document¶
For Each rng In doc.StoryRanges¶
'If appropriate field codes were found,¶
'save the document¶
If DoFind(rng, linkPath) Then doc.Save¶
Do Until rng.NextStoryRange Is Nothing¶
If DoFind(rng, linkPath) Then doc.Save¶
End Sub¶
' * * * * *¶
Function DoFind(rng As Word.Range, linkPath As String) As Boolean¶
'Variable declaration¶
Dim bFound As Boolean¶
Dim fieldCode As String¶
Dim origRng As Word.Range¶
'Determine where the original range first ended¶
' after a successful Find because the range being searched¶
'changes to the found range¶
Set origRng = rng.Duplicate¶
'Make sure field codes are recognized¶
'Else the macro won't find ^d¶
rng.TextRetrievalMode.IncludeFieldCodes = True¶
With rng.Find¶
.Forward = True¶
.MatchCase = False¶
.MatchWholeWord = False¶
.MatchWildcards = False¶
.Text = FindText¶
bFound = .Execute¶
If bFound Then¶
fieldCode = rng.Text¶
Search JabSto ::

Custom Search