VBA 查找并替换文字文本框
VBA find and replace word Text Box
我有一个 Excel 程序。
正在操作一个word文档和find/replace文本。我的代码看起来像这样
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
我有一个 Excel 程序。
正在操作一个word文档和find/replace文本。我的代码看起来像这样
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