Access Topic Custom Properties programatically
Discussion Open
Hi fellow Mindjetters,
I've imported a spreadsheet and added a custom property called 'Keywords' that contains a comma seperated list of Keywords.
I'm now trying to get a Macro to traverse the Map and add the 'Keywords' as Map Markers. I have everything in place except extracting from the Custom Property. Could anyone point me to the correct syntax?
Thanks!
If m_Topic.CustomProperties.Exists("Keywords") Then Keywords = Split(m_Topic.CustomProperties.Item("Keywords").Value, ",") For Each Keyword In Keywords Keyword = Trim(Keyword) If Not IsKeywordAdded(Keyword, mMarkerGrps) Then mMarkerGrps.AddTextLabelMarkerGroup(Keyword) End If Next End If
Hello
As far as I know, the custom property collection does not support access to items by name. You need to find properties by iterating. Sorry, the message board does not paste macro code directly, and strips indentation :(
'#Language "WWB-COM"
Option Explicit
Sub Main
Dim m_Topic As Topic
Dim m_Property As CustomProperty
Set m_Topic = ActiveDocument.Selection.PrimaryTopic
If TopicFindCustomProperty(m_Topic, "Fruit", m_Property) Then
MsgBox(CStr(m_Property.DisplayValue))
End If
End Sub
Function TopicFindCustomProperty(ByVal m_Topic As Topic, ByVal s_Name As String, ByRef m_Property As CustomProperty) As Boolean
Dim m_CP As CustomProperty
TopicFindCustomProperty = False
If m_Topic.DataContainer.DataContainerType = mmDataContainerTypeCustomProperties Then
For Each m_CP In m_Topic.DataContainer.CustomProperties.CustomPropertyCollection
If m_CP.CustomPropertyName = s_Name Then
Set m_Property = m_CP
Return True
End If
Next
End If
End Function
Hello
As far as I know, the custom property collection does not support access to items by name. You need to find properties by iterating. Sorry, the message board does not paste macro code directly, and strips indentation :(
'#Language "WWB-COM"
Option Explicit
Sub Main
Dim m_Topic As Topic
Dim m_Property As CustomProperty
Set m_Topic = ActiveDocument.Selection.PrimaryTopic
If TopicFindCustomProperty(m_Topic, "Fruit", m_Property) Then
MsgBox(CStr(m_Property.DisplayValue))
End If
End Sub
Function TopicFindCustomProperty(ByVal m_Topic As Topic, ByVal s_Name As String, ByRef m_Property As CustomProperty) As Boolean
Dim m_CP As CustomProperty
TopicFindCustomProperty = False
If m_Topic.DataContainer.DataContainerType = mmDataContainerTypeCustomProperties Then
For Each m_CP In m_Topic.DataContainer.CustomProperties.CustomPropertyCollection
If m_CP.CustomPropertyName = s_Name Then
Set m_Property = m_CP
Return True
End If
Next
End If
End Function
Hello
As far as I know, the custom property collection does not support access to items by name. You need to find properties by iterating. Sorry, the message board does not paste macro code directly, and strips indentation :(
'#Language "WWB-COM"
Option Explicit
Sub Main
Dim m_Topic As Topic
Dim m_Property As CustomProperty
Set m_Topic = ActiveDocument.Selection.PrimaryTopic
If TopicFindCustomProperty(m_Topic, "Fruit", m_Property) Then
MsgBox(CStr(m_Property.DisplayValue))
End If
End Sub
Function TopicFindCustomProperty(ByVal m_Topic As Topic, ByVal s_Name As String, ByRef m_Property As CustomProperty) As Boolean
Dim m_CP As CustomProperty
TopicFindCustomProperty = False
If m_Topic.DataContainer.DataContainerType = mmDataContainerTypeCustomProperties Then
For Each m_CP In m_Topic.DataContainer.CustomProperties.CustomPropertyCollection
If m_CP.CustomPropertyName = s_Name Then
Set m_Property = m_CP
Return True
End If
Next
End If
End Function
Hello
As far as I know, the custom property collection does not support access to items by name. You need to find properties by iterating. Sorry, the message board does not paste macro code directly, and strips indentation :(
'#Language "WWB-COM"
Option Explicit
Sub Main
Dim m_Topic As Topic
Dim m_Property As CustomProperty
Set m_Topic = ActiveDocument.Selection.PrimaryTopic
If TopicFindCustomProperty(m_Topic, "Fruit", m_Property) Then
MsgBox(CStr(m_Property.DisplayValue))
End If
End Sub
Function TopicFindCustomProperty(ByVal m_Topic As Topic, ByVal s_Name As String, ByRef m_Property As CustomProperty) As Boolean
Dim m_CP As CustomProperty
TopicFindCustomProperty = False
If m_Topic.DataContainer.DataContainerType = mmDataContainerTypeCustomProperties Then
For Each m_CP In m_Topic.DataContainer.CustomProperties.CustomPropertyCollection
If m_CP.CustomPropertyName = s_Name Then
Set m_Property = m_CP
Return True
End If
Next
End If
End Function
This looks great, but for the poor macro writers among us (ie, me), you can do this fairly easily using SmartRules rather than a macro.
First, create the tag group, then set up the SmartRules. Each of these will use the relevant keyword as a trigger to add the appropriate marker to each topic.
This looks great, but for the poor macro writers among us (ie, me), you can do this fairly easily using SmartRules rather than a macro.
First, create the tag group, then set up the SmartRules. Each of these will use the relevant keyword as a trigger to add the appropriate marker to each topic.
---