简体   繁体   English

替换单词VBA Excel-Microsoft Word

[英]Replace words VBA excel - Microsoft word

I'm trying to search for a word and replace it with nothing: 我正在尝试搜索一个单词并将其替换为空:

objWord.Documents.Open (C:\word.docx)


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

Problem with this is it searches for txt1 first, and if it doesn't find that it searches for txt2 and txt 3 BELOW the txt1 text. 问题是它首先搜索txt1,如果找不到,则搜索txt1文本下方的txt2和txt 3。 I want it to search the WHOLE document for txt1/2/3. 我希望它在整个文档中搜索txt1 / 2/3。 Is this possible? 这可能吗?

This is flagged as Excel which I'm familiar with, it's Word but I'm thinking resetting myrange between each may work: 这被标记为我所熟悉的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM