Home test Word Vba Find and Replace a text
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Find and Replace a text PDF Print E-mail
User Rating: / 1
PoorBest 
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

Attachments:
FileDescriptionFile sizeDownloads
Download this file (VBA Find and Replace Text Macro.doc)VBA find and replace text macroThis document contains a macro that can be used to search and replace a specific string in text files.47 Kb246
 
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade