如何在段落VBA中选择两个单词

时间:2014-03-21 08:35:08

标签: vba word-vba

我的单词中包含以下内容:

“b)VergabeverfahrenÖffentlicheAusschreibung,VOB / A Vergabenummer 13A0295S。”

是否可以在本段中同时选择以下两个单词。

“b)Vergabeverfahren”“Vergabenummer”

原因是我想将选择颜色更改为红色。我可以使用此代码成功选择一个单词。但选择两个单词对我来说有点问题。

这是我的代码:

Selection.Start = singleLine.range.Start
Selection.End = singleLine.range.End


ReplaceText = StrFrmDll ' StrFrmDll contains the paragraph. 


 Selection.Find.ClearFormatting
 With Selection.Find
 .Text = ReplaceText
 .Replacement.Text = ReplaceText
 .Replacement.Font.Hidden = True
 .ClearFormatting
 .Wrap = wdFindContinue
 .Format = True
 .MatchCase = False
 End With
     Selection.Find.Execute Replace:=wdReplaceOne
     Selection.Font.Color = wdColorRed

1 个答案:

答案 0 :(得分:0)

只需做两个Selection.Find的

 Selection.Find.ClearFormatting
 With Selection.Find
 .Text = Vergabeverfahren
 .Replacement.Font.Hidden = True
 .ClearFormatting
 .Wrap = wdFindContinue
 .Format = True
 .MatchCase = False
 End With
     Selection.Find.Execute Replace:=wdReplaceOne
     Selection.Font.Color = wdColorRed

 Selection.Find.ClearFormatting
 With Selection.Find
 .Text = Vergabenummer
 .Replacement.Font.Hidden = True
 .ClearFormatting
 .Wrap = wdFindContinue
 .Format = True
 .MatchCase = False
 End With
     Selection.Find.Execute Replace:=wdReplaceOne
     Selection.Font.Color = wdColorRed