locked
Make a list of phrases from a word document RRS feed

  • Question

  • I have a documents that has hundreds of key phrases. All key phrases start with a bracket ([) and end with a bracket (]). I like to append a list of all these key phrases at the end of the document.  While I do work with Excel and Access VBA, I have never worked with Word VBA.

    Thank you,

    RickHbCa

    Sunday, December 13, 2015 8:06 PM

All replies

  • Here is such a macro:

    Sub ListPhrases()
        Dim rng As Range
        Dim strPhrases As String
        Set rng = ActiveDocument.Content
        With rng.Find
            .ClearFormatting
            .MatchWildcards = True
            .Wrap = wdFindStop
            .Text = "\[*\]"
            Do While .Execute
                strPhrases = strPhrases & vbCr & rng.Text
            Loop
        End With
        ActiveDocument.Content.InsertAfter strPhrases
    End Sub

    If you don't want to include the [ and ] in the list, change the line

        ActiveDocument.Content.InsertAfter strPhrases

    to

        ActiveDocument.Content.InsertAfter Replace(Replace(strPhrases, "[", ""), "]", "")


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, December 13, 2015 10:56 PM