2

MSWord ドキュメント全体でワイルドカードを含むテキストを検索し、見つかった文字列を復元したいと考えています。

そんな感じ:

Sub Macro1()
    Dim c As Range
    Set c = ActiveDocument.Contentsdf
    c.Find.ClearFormatting
    c.Find.Replacement.ClearFormatting
    With c.Find
        .Text = "start[abcde]end"
        .Replacement.Text = ""
        .Forward = True
        .wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False '
    End With

    c.Find.Execute
    While c.Find.Found
        Debug.Print c.Find.TextFound
        c.Find.Execute
    Wend
End Sub

しかし、メソッドc.Find.TextFoundは存在しません。再発せずにテキストを回復する方法はありますSelection.Textか?

4

2 に答える 2

3

これを試して。

Sub Sample()
    Dim c As Range
    Dim StartWord As String, EndWord As String

    StartWord = "Start": EndWord = "End"

    Set c = ActiveDocument.Content
    c.Find.ClearFormatting
    c.Find.Replacement.ClearFormatting
    With c.Find
        .Text = StartWord & "*" & EndWord
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False '
    End With

    c.Find.Execute
    While c.Find.Found
        Debug.Print c.Text
        '~~> I am assuming that the start word and the end word will only
        '~~> be in the start and end respectively and not in the middle
        Debug.Print Replace(Replace(c.Text, StartWord, ""), EndWord, "")
        c.Find.Execute
    Wend
End Sub
于 2012-07-14T17:53:18.020 に答える