| Find and Replace a text |
|
|
|
| Tutorials | |||
|
The function below replaces a particilair text string in a word document.
1 Function FindandReplaceText(ByVal searchStr As String, ByVal replacementStr As String, Optional ByVal doMatchcase As Boolean = False) 2 3 '**************************************** 4 '*** Code from VisibleVisual.com ******** 5 '**************************************** 6 7 Selection.Find.ClearFormatting() 8 Selection.Find.Replacement.ClearFormatting() 9 10 With Selection.Find 11 .Text = searchStr 12 .Replacement.Text = replacementStr 13 .Forward = True 14 .Wrap = wdFindContinue 15 .Format = False 16 .MatchCase = doMatchcase 17 .MatchWholeWord = False 18 .MatchWildcards = False 19 .MatchSoundsLike = False 20 .MatchAllWordForms = False 21 End With 22 23 Selection.Find.Execute(Replace:=wdReplaceAll) 24 25 26 End Function 27 28 29 Sub TestFunction() 30 31 FindandReplaceText("VisibleVisual", "String Replaced", False) 32 33 End Sub
|


