2012-05-23 149 views
1

我有以下脚本,它将查找一个句点,后面跟着2个或更多个空格,但我要查找的是能够查找第一个单词的单词句子,如果它是“医疗”,那么它会改变它。我希望能够利用这个脚本,但我已经可以告诉它是否会是错过的段落的第一个单词,我不知道如何正确搜索“医疗”如何在单词中搜索句子的第一个单词

 With Selection.Find 
    .ClearFormatting 
    .Highlight = False 
    .Replacement.ClearFormatting 
    .Replacement.Highlight = True 
    .Text = (\.)({2,9}) 
    .Replacement.Text = "\1 " 
    .Forward = True 
    .Wrap = wdFindContinue 
    .Format = True 
    .MatchWildcards = True 
    .Execute Replace:=wdReplaceAll 
End With 

我最终找到另一篇文章在link以及与此想出了:

  Dim i As Integer 
Dim doc As Document 
Set doc = ActiveDocument 

For i = 1 To doc.Sentences.Count 
    If doc.Sentences(i).Words(1) = "Medical " Then 
     doc.Sentences(i).Words(1) = "Medical (needs removal) " 
    End If 
    If doc.Sentences(i).Words(1) = "Dental " Then 
     doc.Sentences(i).Words(1) = "Dental (needs removal) " 
    End If 
    If doc.Sentences(i).Words(1) = "Life " Then 
     doc.Sentences(i).Words(1) = "Life (needs removal) " 
    End If 
    If doc.Sentences(i).Words(1) = "Vision " Then 
     doc.Sentences(i).Words(1) = "Vision (needs removal) " 
    End If 
Next 

回答

1

下面是该代码块中的片段:

.Text = (\.)()+Medical 
    .Replacement.Text = \1XX 

XX =无论你想改变的话梅迪奇al to。

(\.)匹配句子结尾。

()+匹配无关的空格。

这应该既解决您的多空间问题,并改变医疗到任何你想要的。

我还没有测试过这个。请谨慎使用。

+0

感谢您的回复! – MBlackburn

+0

你能看看这篇文章吗? [链接](http://stackoverflow.com/questions/10711764/vba-word-find-hyperlinks-if-not-arial-10pt-blue) – MBlackburn

相关问题