Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
|
Lista Forumurilor Pe Tematici
|
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login
POZE MRRRR'S FORUM (VIEW ONLY)
Nu sunteti logat.
|
Nou pe simpatie: beatrice17 din Bucuresti
 | Femeie 24 ani Bucuresti cauta Barbat 24 - 80 ani |
|
TRaP
Moderator
Inregistrat: acum 6 ani
Postari: 795
|
|
Source:
Note: The code below automatically highlights the text in the current highlight color (since default is yellow, it will do yellow). However, if you change the color from the highlight tool on Home tab before running the code, it will highlight the text in that color.
Sub Replace_and_Highlight()
findArray = Array("GSI") 'Array("Red 1", "Blue 1", "Green 1") replArray = Array("Great System Information") 'Array("Red 2", "Blue 2", "Green 2")
For i = 0 To UBound(findArray) Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.Highlight = True
With Selection.Find .Text = findArray(i) .Replacement.Text = replArray(i) .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = True .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With
Selection.Find.Execute Replace:=wdReplaceAll Next i
End Sub |
Modificat de TRaP (acum 6 ani)
|
|
pus acum 6 ani |
|
TRaP
Moderator
Inregistrat: acum 6 ani
Postari: 795
|
|
To have the color always switched to the one you desire inside the code, and not have to always select it before running the code, you can put one of the following lines before line Selection.Find.Replacement.Highlight = True
Options.DefaultHighlightColorIndex = wdBrightGreen Options.DefaultHighlightColorIndex = wdTurquoise Options.DefaultHighlightColorIndex = wdPink Options.DefaultHighlightColorIndex = wdBlue Options.DefaultHighlightColorIndex = wdRed Options.DefaultHighlightColorIndex = wdDarkBlue Options.DefaultHighlightColorIndex = wdTeal Options.DefaultHighlightColorIndex = wdGreen Options.DefaultHighlightColorIndex = wdViolet Options.DefaultHighlightColorIndex = wdDarkRed Options.DefaultHighlightColorIndex = wdDarkYellow Options.DefaultHighlightColorIndex = wdGray50 Options.DefaultHighlightColorIndex = wdGray25 Options.DefaultHighlightColorIndex = wdBlack Options.DefaultHighlightColorIndex = wdNoHighlight
|
|
pus acum 6 ani |
|
TRaP
Moderator
Inregistrat: acum 6 ani
Postari: 795
|
|
To insert words via InputBox, separated by commas, see source:
The code from post 1 updated with input boxes for find terms and replace terms is below:
Sub Replace_and_Highlight()
Dim findArray, replArray, i As Long
findArray = InputBox(prompt:="Put list of terms to be replaced, separated by commas", Title:="What to find?", Default:="") replArray = InputBox(prompt:="Put list of terms to replace with, separated by commas", Title:="What to replace with?", Default:="")
For i = 0 To UBound(Split(findArray, ",")) Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting ' Options.DefaultHighlightColorIndex = wdBrightGreen ' Options.DefaultHighlightColorIndex = wdTurquoise ' Options.DefaultHighlightColorIndex = wdPink ' Options.DefaultHighlightColorIndex = wdBlue ' Options.DefaultHighlightColorIndex = wdRed ' Options.DefaultHighlightColorIndex = wdDarkBlue ' Options.DefaultHighlightColorIndex = wdTeal ' Options.DefaultHighlightColorIndex = wdGreen ' Options.DefaultHighlightColorIndex = wdViolet ' Options.DefaultHighlightColorIndex = wdDarkRed ' Options.DefaultHighlightColorIndex = wdDarkYellow ' Options.DefaultHighlightColorIndex = wdGray50 ' Options.DefaultHighlightColorIndex = wdGray25 ' Options.DefaultHighlightColorIndex = wdBlack ' Options.DefaultHighlightColorIndex = wdNoHighlight Selection.Find.Replacement.Highlight = True
With Selection.Find .Text = Split(findArray, ",")(i) .Replacement.Text = Split(replArray, ",")(i) .Forward = True .Wrap = wdFindContinue 'wdFindStop .Format = True .MatchCase = True .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With
Selection.Find.Execute Replace:=wdReplaceAll Next i
End Sub |
Modificat de TRaP (acum 6 ani)
|
|
pus acum 6 ani |
|