2012-05-23 2 views
1

두 개 이상의 공백이있는 마침표를 찾을 수있는 다음 스크립트를 가지고 있지만 찾고있는 것은 첫 번째 단어를 찾을 수 있도록하는 것입니다. 문장이 "의학적"이라면 그것을 바꿀 것입니다. 나는이 대본을 활용하기를 바랬지 만 이미 놓친 단락의 첫 번째 단어인지 여부는 이미 알 수 있습니다. "의학"에 대한 검색 방법을 잘 모르겠습니다.단어의 문장 첫 번째 단어를 검색하는 방법

 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 = 당신이 단어 메딕을 변경하려면 무엇이든은 알.

(\.)은 문장의 끝과 일치합니다.

()+은 외부 공간과 일치합니다.

이렇게하면 여러 공백 문제가 해결되고 Medical을 원하는대로 변경할 수 있습니다.

테스트하지 않았습니다. 재량권을 행사하십시오.

+0

답장을 보내 주셔서 감사합니다. – MBlackburn

+0

이 게시물을 보시겠습니까? [link] (http://stackoverflow.com/questions/10711764/vba-word-find-hyperlinks-if-not-arial-10pt-blue) – MBlackburn

관련 문제