VBA 将多个内容控件添加到 Word 中的单个 Table 单元格
VBA to Add Multiple Content Controls to a Single Table Cell in Word
我需要使用 VBA 将多个内容控件和附加文本添加到单个 table 单元格中。这是我需要的示例:
Moby Dick 已被 2 人阅读并给出了 3 的平均分(满分 5)
我知道我可以使用以下语法添加单个内容控件:
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Book Name"
.Tag = "title"
End With
如果我的范围设置为单元格,我将如何使以下伪代码工作:
Set rng = objDoc.Tables(1).Cell(2, 1).Range
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Book Name"
.Tag = "title"
End With
" has been read by "
With rng.ContentControls.Add(wdContentControlRichText)
.title = "People Count"
.Tag = "count"
End With
" people who have given it an average score of "
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Score"
.Tag = "score"
End With
" out of 5"
这是一些实际的代码。它将第三个 insertafter 和内容控件放在第二个 insertafter 和第二个内容控件之间
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Asset ID"
.Tag = "asset_id"
End With
rng.InsertAfter " | Rev. "
rng.Collapse Direction:=wdCollapseEnd
rng.Move wdCharacter, -1
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Revison Number"
.Tag = "revision_num"
End With
rng.InsertAfter " | Effective Date: "
rng.Collapse Direction:=wdCollapseEnd
rng.Move wdCharacter, -1
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Effective Date"
.Tag = "effective_date"
End With
试试这个:
Set rng = objDoc.Tables(1).Cell(2, 1).Range
rng.Collapse wdCollapseStart
With rng.ContentControls.Add(wdContentControlRichText)
.Title = "Effective Date"
.Tag = "effective_date"
.SetPlaceholderText Text:="Effective date"
End With
rng.Text = " | Effective Date: "
rng.Collapse wdCollapseStart
With rng.ContentControls.Add(wdContentControlRichText)
.Title = "Revison Number"
.Tag = "revision_num"
.SetPlaceholderText Text:="Rev Num"
End With
rng.Text = " | Rev. "
rng.Collapse wdCollapseStart
With rng.ContentControls.Add(wdContentControlRichText)
.Title = "Asset ID"
.Tag = "asset_id"
.SetPlaceholderText Text:="Asset ID"
End With
我需要使用 VBA 将多个内容控件和附加文本添加到单个 table 单元格中。这是我需要的示例:
我知道我可以使用以下语法添加单个内容控件:
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Book Name"
.Tag = "title"
End With
如果我的范围设置为单元格,我将如何使以下伪代码工作:
Set rng = objDoc.Tables(1).Cell(2, 1).Range
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Book Name"
.Tag = "title"
End With
" has been read by "
With rng.ContentControls.Add(wdContentControlRichText)
.title = "People Count"
.Tag = "count"
End With
" people who have given it an average score of "
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Score"
.Tag = "score"
End With
" out of 5"
这是一些实际的代码。它将第三个 insertafter 和内容控件放在第二个 insertafter 和第二个内容控件之间
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Asset ID"
.Tag = "asset_id"
End With
rng.InsertAfter " | Rev. "
rng.Collapse Direction:=wdCollapseEnd
rng.Move wdCharacter, -1
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Revison Number"
.Tag = "revision_num"
End With
rng.InsertAfter " | Effective Date: "
rng.Collapse Direction:=wdCollapseEnd
rng.Move wdCharacter, -1
With rng.ContentControls.Add(wdContentControlRichText)
.title = "Effective Date"
.Tag = "effective_date"
End With
试试这个:
Set rng = objDoc.Tables(1).Cell(2, 1).Range
rng.Collapse wdCollapseStart
With rng.ContentControls.Add(wdContentControlRichText)
.Title = "Effective Date"
.Tag = "effective_date"
.SetPlaceholderText Text:="Effective date"
End With
rng.Text = " | Effective Date: "
rng.Collapse wdCollapseStart
With rng.ContentControls.Add(wdContentControlRichText)
.Title = "Revison Number"
.Tag = "revision_num"
.SetPlaceholderText Text:="Rev Num"
End With
rng.Text = " | Rev. "
rng.Collapse wdCollapseStart
With rng.ContentControls.Add(wdContentControlRichText)
.Title = "Asset ID"
.Tag = "asset_id"
.SetPlaceholderText Text:="Asset ID"
End With