将数据插入单词 [英] Inserting data into word
问题描述
我成功使用以下内容将数据插入包含书签的单词:
I have been successful using the following to insert data to word with Bookmarks:
selection.goto内容:= wdGoToBookmark,名称:=" LastName"
selection.TypeText" Smith" k
selection.goto What:=wdGoToBookmark, Name:="LastName"
selection.TypeText "Smith"k
但我的办公室使用内容控件的模板。 我可以调用它们并将数据放入内容控件中,就像使用书签一样吗?
But my office uses templates with Content Controls. Can I call them and place data in the content control like with Bookmarks?
推荐答案
内容控制代码不同。 您必须执行以下操作:
Content Controls code is different. You'd have to do something like:
Dim oApp   作为对象'Word.application
Dim oDoc 作为对象'Word.Document
On Error Resume Next
设置oApp = GetObject(,"Word.Application")
如果Err.Number<> 0然后 'Word没有运行,所以启动它
设置oApp = CreateObject(" Word.Application")
结束如果是
On Error GoTo 0
Dim oApp As Object 'Word.application
Dim oDoc As Object 'Word.Document
On Error Resume Next
Set oApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't running so start it
Set oApp = CreateObject("Word.Application")
End If
On Error GoTo 0
设置oDoc = oApp.Documents.Open(sFileName)
oApp.Visible = True
Set oDoc = oApp.Documents.Open(sFileName)
oApp.Visible = True
然后对于Text CC你会做类似的事情:
Then For Text CC you'd do something like:
oDoc .SelectContentControlsByTitle(" NameOfCC")(1).Range.Text =" Value"
oDoc.SelectContentControlsByTitle("NameOfCC")(1).Range.Text = "Value"
对于CC复选框你要做什么类似于:
For CC Check boxes you'd do something like:
oDoc.SelectContentControlsByTitle(" NameOfCC")(1).Checked = True / False
oDoc.SelectContentControlsByTitle("NameOfCC")(1).Checked = True/False
这篇关于将数据插入单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!