簡體   English   中英

使用 excel 在 word 中查找和替換 DYNAMIC 文本

[英]Find and Replace DYNAMIC text in word using excel

我們可以使用替換 Word 文檔中的 static 文本

Dim obj_word As New Word.Application
Dim doc_word As Word.Document

Set doc_word = obj_word.Documents.Open(file_path)
doc_word.Content.Find
    .Text = "TEXT1"
    .Replacement.Text = "TEXT2"
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceOne
End With

但是如果動態文本需要替換為另一個文本呢?

例如我正在創建一個單詞模板,動態單詞是 {Sheet1-D8}

我想用 excel sheet1 range D8 中的單詞替換它。

有人可以幫忙嗎?

萬分感謝:)

請嘗試下一個方法:

Dim strAddr As String, strReplace as String, arrAdr
strAddr = "{sheet1-D8}"
arrAdr = split(strAddr,"-")
strReplace = Worksheets(mid(2,arrAdr(0))).Range(left(arrAdr(1), len(arrAdr(1) -1)).value

謝謝大家的回復。 但我通過下面的鏈接找到了我的問題的解決方案。 (訣竅是使用通配符)

使用通配符在文檔中查找字符串; 返回完整字符串 VBA

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM