Compartilhar via


CustomProperties Collection

Word Developer Reference

A collection of CustomProperty objects that represents the properties related to a smart tag. The CustomProperties collection includes all the smart tag custom properties in a document.

Remarks

Use the Properties property to return a single CustomProperties object. Use the Add method of the CustomProperties object with to create a custom property from within a Microsoft Word Visual Basic for Applications project. This example creates a new property for the first smart tag in the active document and displays the XML code used for the tag.

Visual Basic for Applications
  Sub AddProps()
    With ActiveDocument.SmartTags(1)
        .Properties.Add Name:="President", Value:=True
        MsgBox "The XML code is " & .XML
    End With
End Sub

Use Properties(Index) to return a single property for a smart tag, where Index is the number of the property. This example displays the name and value of the first property of the first smart tag in the current document.

Visual Basic for Applications
  Sub ReturnProps()
    With ActiveDocument.SmartTags(1).Properties(1)
        MsgBox "The Smart Tag name is: " & .Name & vbLf & .Value
    End With
End Sub

Use the Count property to return the number of custom properties for a smart tag. This example loops through all the smart tags in the current document and then lists in a new document the name and value of the custom properties for all smart tags that have custom properties.

Visual Basic for Applications
  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

See Also