通过标题(或标签)获取 ContentControl

iva*_*eev 4 vba ms-word

Document.ContentControls 集合不支持按名称检索项目,仅支持按索引。

我仍然可以ContentControl通过用户定义的标识符获取特定信息以保持代码可读吗?(例如,内容控制标题——Office 论坛女士声称只能一一尝试。)

iva*_*eev 8

Document.SelectContentControlsByTitle()Document.SelectContentControlsByTag()此方法。

由于控件的两个属性都不能保证是唯一的,因此它们都返回ContentControls结果的集合。像这样的函数可用于验证结果是否存在且唯一:

Public Function CCSingle(source As ContentControls) As ContentControl
    Select Case Sgn(source.Count - 1)
    Case -1
        '9 = subscript out of range
        'http://onlinelibrary.wiley.com/doi/10.1002/9781118257616.app3/pdf
        Call Err.Raise(9, , "Identifier not found")
    Case 1
        Call Err.Raise(9, , "Identifier not unique")
    Case Else
        Set CCSingle = source.Item(1)
    End Select
End Function
Run Code Online (Sandbox Code Playgroud)