Customization based on text in sibling topic

  • 1
  • Question
  • Updated 1 week ago
  • (Edited)
I need help with a custom feature I am looking for.

 When I add topic and write text in it, If  the text I write the selected topic is same as in any text in any of the sibling topics, then I need the text of the current/selected topic to be modified as below.

If the text in current topic  is AA and there already a sibling topic with text AA i need the current topic's text to change to AA1. 


I want to write a marco for the same. Any inputs would be helpful. Thank you. 
Photo of gthghcdng

gthghcdng

  • 5 Posts
  • 0 Reply Likes

Posted 1 week ago

  • 1
Photo of Nick Duffill

Nick Duffill, Champion

  • 518 Posts
  • 173 Reply Likes
A macro could do the processing you require, but macros only run when launched from a command in the user interface. They do not respond to events, such as a topic modification event. This might not be what you need.

Some starter code as a hint:
Sub Main
    Dim m_Sibling As Topic

    With ActiveDocument.Selection.PrimaryTopic
        If (Not .IsCentralTopic) And (Not .IsFloatingTopic) And Not (.IsCalloutTopic) Then
            For Each m_Sibling In .ParentTopic.AllSubTopics
                If Not (m_Sibling Is ActiveDocument.Selection.PrimaryTopic) Then
                    If m_Sibling.Text = .Text Then
                        ' duplicated text, do something
                        .Text = .Text & "1"
                    End If
                End If
            Next
        End If
    End With
End Sub
The above does not deal with the situation where "AA1" has already been used.


Photo of gthghcdng

gthghcdng

  • 5 Posts
  • 0 Reply Likes
Thank you Nick for the super fast reply. The information you have provided is quite valuable to me and the code hint as well. I will try to build on the hint you've given. Thanks again.