目的:
选择名为'ddMyDropdown的控制控件(下拉列表)并添加列表。
唯一不起作用的部分是选择内容控制下拉列表。我希望手中的控件在手中,所以它在正确的位置。
尝试: 我确实有Set objCC = ActiveDocument.ContentControls.Add(ddMyDropdown)但这会添加一个新的内容控件,而不是“编辑”当前的内容控件。
代码:
Dim objCC As ContentControl
Dim objLE As ContentControlListEntry
Dim objMap As XMLMapping
Set objCC = ActiveDocument.SelectContentControlsByTitle("ddMyDropdown")
'我也尝试过SelectContentControlsByTag,属性有标题和标签 objCC.DropdownListEntries.Clear
'List entries
objCC.DropdownListEntries.Add "--PLEASE SELECT--"
objCC.DropdownListEntries.Add "Cat"
objCC.DropdownListEntries.Add "Dog"
objCC.DropdownListEntries.Add "Horse"
objCC.DropdownListEntries.Add "Monkey"
objCC.DropdownListEntries.Add "Snake"
objCC.DropdownListEntries.Add ("Other")
参考: https://msdn.microsoft.com/en-us/library/office/ff836949.aspx
答案 0 :(得分:0)
以下有效,但有办法不循环所有内容控件......
Dim objCC As ContentControl
Dim objLE As ContentControlListEntry
Dim objMap As XMLMapping
For Each objCC In ActiveDocument.ContentControls
If objCC.Title = "ddDropdown" Then
objCC.DropdownListEntries.Add "--PLEASE SELECT--"
objCC.DropdownListEntries.Add "Cat"
objCC.DropdownListEntries.Add "Dog"
objCC.DropdownListEntries.Add "Horse"
objCC.DropdownListEntries.Add "Monkey"
objCC.DropdownListEntries.Add "Snake"
objCC.DropdownListEntries.Add ("Other")
Next objCC
End Sub