Share via


Replacement プロパティ

Microsoft Word Visual Basic リファレンス

Replacement プロパティ

置換操作の条件を含む Replacement オブジェクトを取得します。

expression.Replacement

*expression *  必ず指定します。Find オブジェクトを表すオブジェクト式を指定します。

使用例

次の使用例は、作業中の文書から太字の書式を削除します。Bold プロパティの値は、Find オブジェクトでは TrueReplacement オブジェクトでは False です。

With ActiveDocument.Content.Find
    .ClearFormatting
    .Font.Bold = True
    With .Replacement
        .ClearFormatting
        .Font.Bold = False
    End With
    .Execute FindText:="", ReplaceWith:="", Format:=True, _
        Replace:=wdReplaceAll
End With
		

次の使用例は、作業中の文書で単語 "Start" をすべて検索し、"End" に置き換えます。検索では、書式は無視し、大文字と小文字を区別して検索文字列 ("Start") と一致する文字列を検索します。

Set myRange = ActiveDocument.Range(Start:=0, End:=0)
With myRange.Find
    .ClearFormatting
    .Text = "Start"
    With .Replacement
        .ClearFormatting
        .Text = "End"
    End With
    .Execute Replace:=wdReplaceAll, _
        Format:=True, MatchCase:=True, _
        MatchWholeWord:=True
End With