替换单词VBA excel - Microsoft Word

时间:2018-02-26 18:51:37

标签: excel vba

我试图搜索一个单词并将其替换为任何单词:

Sub Convert()
    Dim cell As Range
    Dim delim As String

    delim = "++^||"
    For Each cell In Range("A2", Cells(Rows.Count, "A").End(xlUp))
        Debug.Print Join(Application.Transpose(Application.Transpose(Range(cell, cell.End(xlToRight)).value)), delim) & delim
    Next
End Sub

问题在于它首先搜索txt1,如果它没有找到它搜索txt1文本下面的txt2和txt 3。我希望它在整个文档中搜索txt1 / 2/3。这可能吗?

1 个答案:

答案 0 :(得分:0)

这被标记为我熟悉的Excel,它是Word,但我想在每个之间重置myrange可能有效:

    With objWord.ActiveDocument
    Set myrange = .Content
    With myrange.Find
        .Execute FindText:=txt1, ReplaceWith:=""
    End With
    Set myrange = .Content
    With myrange.Find
        .Execute FindText:=txt2, ReplaceWith:=""
    End With
    Set myrange = .Content
    With myrange.Find
        .Execute FindText:=txt3, ReplaceWith:=""
    End With
    End With