SmartTag![]() ![]() ![]() |
该集合由 CustomProperty 对象组成,这些对象代表与智能标记相关的属性。CustomProperties 集合包含文档中所有智能标记的自定义属性。
使用 Properties 属性可返回一个单独的 CustomProperties 对象。使用 CustomProperties 对象的 Add 方法可从 Microsoft Word Visual Basic for Applications 项目中创建一个自定义属性。本示例为活动文档中的第一个智能标记创建一个新的属性,并显示用于该标记的 XML 代码。
Sub AddProps()
With ThisDocument.SmartTags(1)
.Properties.Add Name:="President", Value:=True
MsgBox "The XML code is " & .XML
End With
End Sub
使用 Properties(index) 可返回智能标记的一个单独属性,其中 index 是该属性的编号。本示例显示当前文档中第一个智能标记的第一个属性的名称和属性值。
Sub ReturnProps()
With ThisDocument.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 ThisDocument.SmartTags.Count
With ThisDocument.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