@m111

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Word VBA 下線付き文字の検索と置換

解決したいこと

下記を実行したいです。
1.文書内で下線付き文字を検索する
2.文書内の全ての下線付き文字を「削除」(下線なし)に置き換える

発生している問題・エラー

下線付き文字の検索、置換ができない

該当するソースコード

With Selection.Find
        .Text = ""
     .Font.Underline = True
    .Replacement.Text = "削除"
        .Forward = True
        .Wrap = 1 'wdFindContinue
        .Format = True
        .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
End With
Find.Execute

自分で試したこと

上記のコードで試してみましたが、下線付き文字の検索ができず困っています。
ご教授お願い致します。

0 likes

3Answer

以下のコードをお試しください。
コメントは、置換ダイアログの各項目に該当します。

    With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        
        '検索オプション
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .MatchFuzzy = False
        
        '検索する文字列
        .Font.Underline = wdUnderlineSingle
        .Text = ""
        
        '置換後の文字列
        .Replacement.Font.Underline = wdUnderlineNone
        .Replacement.Text = "削除"
        
        'すべて置換
        .Execute Replace:=wdReplaceAll
    End With


image.png

0Like

Your answer might help someone💌