How can I collect a list of tags from a document and build a list ofthem for filling a ComboBox from

Discussion in 'Word VBA' started by Ricky Marek, Oct 16, 2013.

  1. Ricky Marek

    Ricky Marek Guest

    How can I get a list of unique tags collected from a document by running a search operation.

    The tags are composed a single word enclosed by '[#' and ']' or '[!' and ']'.
    For example [#ABC], [#FOO], [!FOO], [!BAR], [!WXYZ].

    The tags may appear more than once in the document, therefore I should ignore the duplicated ones and build a unique list of tags. (The tags collected from the example above would be "ABC", "BAR", "FOO", "WXYZ")

    It would be nice to have them sorted as well :)

    The idea is to generate the list and use it to fill a user form combo box, filled dynamically.

    Can you give an idea how to run this?

    The code I was using is similar to:

    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
    .Text = "(\[[!#])(*)(\])"
    .Replacement.Text = ""
    .Wrap = wdFindContinue
    .MatchWildcards = True
    End With

    But this runs on all the document and removes the tag.. How do I do for collecting the tag without removing?


    Thanks in advance.

    --- Ricky Marek.
     
    Ricky Marek, Oct 16, 2013
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.