N
Nomey
Dear all,
I need to build a code to search a predefined set of strings in a document and replace them by another predefined set of strings.
Example:
strS is (vssen | vsen | vss | vss. | vs. | vs | v. | v )
strR is (vÿerÿssen | vÿerÿsen | etcetera...)
strS (search strings) and strR (replacement strings) have the same number of elements. The first element of strS should be replaced by the first element of strR, etcetera, but
1) how do I set a string variable to a limited list of search/replacement strings. Would that be an array? and
2) why does the .HighlightColorIndex = wdNoHighlight not compile in my first attempt (see below)?
Sub Vop()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
'declare variables for search and replace texts
Dim strS, strR As String
Dim lngC As Long
'for loop to execute F&R with all strings
With rTmp.Find
.Text = strS
.Replacement.Text = strR
'add .HighlightColorIndex = wdNoHighlight -> does not compile
.MatchWholeWord = True
.MatchCase = False
.MatchWildcards = False
While .Execute
rTmp.start = rTmp.End
rTmp.End = ActiveDocument.Range.End
Wend
End With
End Sub
Best regards - Shirley Nomey
I need to build a code to search a predefined set of strings in a document and replace them by another predefined set of strings.
Example:
strS is (vssen | vsen | vss | vss. | vs. | vs | v. | v )
strR is (vÿerÿssen | vÿerÿsen | etcetera...)
strS (search strings) and strR (replacement strings) have the same number of elements. The first element of strS should be replaced by the first element of strR, etcetera, but
1) how do I set a string variable to a limited list of search/replacement strings. Would that be an array? and
2) why does the .HighlightColorIndex = wdNoHighlight not compile in my first attempt (see below)?
Sub Vop()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
'declare variables for search and replace texts
Dim strS, strR As String
Dim lngC As Long
'for loop to execute F&R with all strings
With rTmp.Find
.Text = strS
.Replacement.Text = strR
'add .HighlightColorIndex = wdNoHighlight -> does not compile
.MatchWholeWord = True
.MatchCase = False
.MatchWildcards = False
While .Execute
rTmp.start = rTmp.End
rTmp.End = ActiveDocument.Range.End
Wend
End With
End Sub
Best regards - Shirley Nomey