本文介绍了通过标题(或标签)获取ContentControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Document.ContentControls collection doesn't support item retrieval by name, only by index.

我仍然可以通过用户定义的标识符获取特定的ContentControl以便保持代码可读性吗? (例如,内容控件标题-Office Forums女士声称只能一一尝试.)

Can I still get a specific ContentControl by a user-defined identifier so as to keep code readable? (e.g. Content control titles - Ms Office Forums claims it's only possible to try them one by one.)

推荐答案

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

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

Since neither property of a control is guaranteed to be unique, both return a ContentControls collection of results. A function like this can be used to verify that the result exists and is unique:

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

这篇关于通过标题(或标签)获取ContentControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 12:23