CustomProperty 对象的集合,表示与智能标记相关的属性。 自定义属性 集合包含文档中的所有智能标记的自定义属性。
备注
使用 属性 可返回一个 自定义属性 对象。 使用 Add 方法的 自定义属性 的对象来创建自定义属性在 Microsoft Word Visual Basic for Applications 项目。 本示例创建活动文档中第一个智能标记的新属性,并显示用于该标记的 XML 代码。
Sub AddProps()
With ActiveDocument.SmartTags(1)
.Properties.Add Name:="President", Value:=True
MsgBox "The XML code is " & .XML
End With
End Sub
使用 属性 (索引) 返回单个智能标记,属性索引所在的属性数。 本示例显示当前文档中的名称和第一个智能标记的第一个属性的值。
Sub ReturnProps()
With ActiveDocument.SmartTags(1).Properties(1)
MsgBox "The Smart Tag name is: " & .Name & vbLf & .Value
End With
End Sub
使用 Count 属性可返回智能标记的自定义属性的数目。 此示例循环访问当前文档中的所有智能标记,然后列出在新文档的名称和所有具有自定义属性的智能标记的自定义属性的值。
Sub SmartTagsProps()
Dim docNew As Document
Dim stgTag As SmartTag
Dim stgProp As CustomProperty
Dim intTag As Integer
Dim intProp As Integer
Set docNew = Documents.Add
'Create heading info in new document
With docNew.Content
.InsertAfter "Name" & vbTab & "Value"
.InsertParagraphAfter
End With
'Loop through smart tags in current document
For intTag = 1 To ActiveDocument.SmartTags.Count
With ActiveDocument.SmartTags(intTag)
'Verify that the custom properties
'for smart tags is greater than zero
If .Properties.Count > 0 Then
'Loop through the custom properties
For intProp = 1 To .Properties.Count
'Add custom property name to new document
docNew.Content.InsertAfter .Properties(intProp) _
.Name & vbTab & .Properties(intProp).Value
docNew.Content.InsertParagraphAfter
Next
Else
'Display message if there are no custom properties
MsgBox "There are no custom properties for the " & _
"smart tags in your document."
End If
End With
Next
'Convert the content in the new document into a table
docNew.Content.Select
Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2
End Sub
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。