[英]VBA find and replace word Text Box
我有一個 Excel 程序。
這是操作word文檔並查找/替換文本。 我的代碼看起來像這樣
Dim wApp As Word.Application
Dim wDoc As Word.Document
Set wApp = CreateObject("Word.Application")
wApp.Visible = False
Set wDoc = wApp.Documents.Open(myFile)
With wDoc.Content.Find
.Text = "<Customer Name>"
.Replacement.Text = "Customer Name"
.Wrap = wdFindContinue
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
.Text = "<Billing Address>"
.Replacement.Text = "Billing Address"
.Wrap = wdFindContinue
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
哪個工作得很好。
但是,word 文檔的文本框中有一些單詞,我想查找和替換這些單詞,但我無法使其工作(上面的代碼僅搜索 word 文檔的主體,而不搜索文本框)
我試過
wDoc.Shapes.Range(Array("Text Box 14")).Select
With wDoc.Selection.Find
.Text = "<Profile Code>"
.Replacement.Text = "Profile Code"
.Wrap = wdFindContinue
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
但這沒有用。 我收到一個對象不支持此屬性或方法錯誤消息
請幫忙!
如果文本框命名為“文本框 14”,以下內容應該對您有用(在 O365 中對我有用)
With wDoc.Shapes("Text Box 14").TextFrame.TextRange.Find
.Text = "<Profile Code>"
.Replacement.Text = "Profile Code"
.Wrap = wdFindContinue
.MatchWholeWord = True
.Execute Replace:=wdReplaceAll
End With
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.