2012-05-23 61 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