从 Excel VBA 编辑 Word 中的 ContentControl
我想在 Word 应用程序中编辑纯文本内容控件。
我搜索过,但目标 Word 文档中的“纯文本内容控件”似乎没有响应
objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text
我尝试使用“ActiveDocument”选项,但我希望它不与活动选项一起使用。
VBA Excel 中的代码:
Sub dataToWord()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\Users\ASUS\Documents\Excell to Word - Copy\WordTesting1.docx")
objWord.Visible = True
objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text = "I want to type some text here"
objDoc.Save
objDoc.Close
End Sub
我得到:
运行时错误“445”:
对象不支持此操作
它指的是该行
objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text = "I want to type some text here"
I want to edit the plain text content control in my Word application.
I searched but it seems The "plain text content control" in my target Word document does not respond to
objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text
I tried with "ActiveDocument" options but I want it not to work with the active ones.
Code in VBA Excel:
Sub dataToWord()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\Users\ASUS\Documents\Excell to Word - Copy\WordTesting1.docx")
objWord.Visible = True
objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text = "I want to type some text here"
objDoc.Save
objDoc.Close
End Sub
I get:
Run-time error '445':
Object doesn't support this action
It refers to the line
objDoc.SelectContentControlsByTag("Name").Item(1).Range.Text = "I want to type some text here"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经禁用了 WPS 应用程序。它工作正常..它似乎与微软Word应用程序冲突..
I have disabled the WPS app . and it worked fine.. it seems it is in conflict with the microsoft word application..