1

ピリオドの後に 2 つ以上のスペースが続く次のスクリプトがありますが、私が探しているのは、文の最初の単語を検索できるようにすることであり、それが「Medical」の場合はそれを変更します。このスクリプトを活用したいと思っていましたが、それが段落の最初の単語であるかどうかはすでにわかります。また、「.Medical」を適切に検索する方法もわかりません。

     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

リンクで別の投稿を見つけて、これを思いつきました:

         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
4

1 に答える 1

1

そのコード ブロックのスニペットを次に示します。

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

XX = Medical という単語を変更したいもの。

(\. )文末にマッチします。

( )+不要なスペースに一致します。

これにより、複数のスペースの問題が修正され、医療が必要なものに変更されます。

私はこれをテストしていません。裁量でご利用ください。

于 2012-05-23T19:14:52.757 に答える