Microsoft Office Tutorials and References
In Depth Information
Finding and Replacing in Multiple Documents
'Check whether it's a field that links¶
'in an outside file¶
If InStr(LCase(fieldCode), "includetext") <> 0 _¶
Or InStr(LCase(fieldCode), "includepicture") <> 0 _¶
Or InStr(LCase(fieldCode), "link") <> 0 Then¶
'If it is, replace the old path with the new¶
rng.Fields(1).Code.Text = NewFieldCode(fieldCode,
linkPath)¶
rng.Fields(1).Update¶
DoFind = True¶
End If¶
End If¶
End With¶
'Extend the search range again to¶
'the end of the original range¶
rng.Collapse wdCollapseEnd¶
rng.End = origRng.End¶
Loop While bFound¶
End Function¶
' * * * * *¶
Function NewFieldCode(ByRef fieldCode As String, linkPath As String) As
String¶
'Variable declaration¶
Dim startPos As Long, endPos As Long¶
Dim newCode As String, docName As String¶
'Find where the first space after the field name is¶
startPos = InStr(3, fieldCode, " ")¶
'If the file path contains spaces, it will¶
'be enclosed in "quotes"¶
'Get the position at the end of the path¶
'either the closing quote, or the first space¶
If Mid(fieldCode, startPos + 1, 1) = Chr$(34) Then¶
endPos = InStr(startPos + 2, fieldCode, Chr$(34)) + 1¶
Else¶
endPos = InStr(startPos + 2, fieldCode, " ")¶
End If¶
'doc name is from the end of the path to¶
'the first backslash¶
docName = Mid(fieldCode, _¶
InStrRev(fieldCode, "\", endPos) + 1, _¶
endPos - InStrRev(fieldCode, "\", endPos) - 2)¶
'Now put all the parts back together, with the¶
'new link path¶
newCode = Mid(fieldCode, 2, startPos - 1) & _¶
Chr$(34) & linkPath & "\" & docName & Chr$(34) & _¶
Mid(fieldCode, endPos, Len(fieldCode) - endPos)¶
'Fieldcodes in Word need double backslashes¶
newCode = DoubleBackslashes(newCode)¶
NewFieldCode = newCode¶
End Function¶
Wrd
Search JabSto ::




Custom Search