Consulting

Results 1 to 3 of 3

Thread: Glossary generating Macro Help

  1. #1

    Lightbulb Glossary generating Macro Help

    Hey everyone,


    I am pre-novice at VBA, so I would appreciate if I can get some help in creating a macro for the following scenario:


    I have a list of technical words/phrases with their alternatives (for illustration purposes, see below)


    Paper - report, transcript, summary


    Financial documents - balance-sheet, income statement, forecast, budget


    Expert - professional, teacher, experienced






    Each word has other alternatives (synonyms) and what I would like to do it create a macro such that whenever I run it (on a word file), it highlights all the occurrences of the words and displays the list of those words and their alternatives at the bottom of the document (preferably separated by a line)


    But only the words used in the document should be displayed. For example, if a document had "financial" and "expert" in it, then these words with all their alternatives should be displayed and since "paper" was not in the document macro should skip that.

    Any thoughts how I can do that macro for word?




    Any input is highly appreciated!




    Below is the macro I have for highlighting words so far. I will like to add more coding to this and the suggested replacements for the highlighted words.




    Sub rkis()
     
    Dim range As range
    Dim i As Long
    Dim TargetList
     
    TargetList = Array("expert", "assist", "review", "compile", "confirm", "audit", "attest", "assurance", "certify", "examine", "verify", "validate", "in our opinion", "ensure", "guarantee", "satisfy", "ascertain/know your needs", "best possible", "best efforts", "highest standards", "unequalled", "incomporable", "maximize", "optimize", "minimize", "determine", "select", "incomparable", "subject matter expert", "state-of-the-art", "cutting-edge", "Partner with", "Optimum solution", "the solution will achieve", "to your satisfaction", "will meet all your needs", "negotiate", "identify any issues", "validate the plan", "we will develop a series of workshops", "we will prepare slides and materials to be used during the workshops", "we will assist in the completion of the three-year Plan") ' put list of terms to find here
     
    For i = 0 To UBound(TargetList)
     
    Set range = ActiveDocument.range
     
    With range.Find
    .Text = TargetList(i)
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
     
    Do While .Execute(Forward:=True) = True
    range.HighlightColorIndex = wdYellow
     
    Loop
     
    End With
    Next
     
    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Try:
    Sub CompileDocumentGlossary()
    Application.ScreenUpdating = False
    Dim DocSrc As Document, StrIn, StrTmp As String, StrOut As String, j As Long
     'Load the strings from the reference doc into a text string to be used as an array.
    Set DocSrc = Documents.Open("Drive:\FilePath\Glossary.doc", ReadOnly:=True, AddToRecentFiles:=False, Visible:=False)
    StrIn = FRDoc.Range.FormattedText
    DocSrc.Close False
    Set DocSrc = Nothing
    Options.DefaultHighlightColorIndex = wdYellow
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .MatchWholeWord = True
        .MatchCase = True
        .Replacement.Highlight = True
        'Process each word from the terms List. Strings delimited by ' - ' are assumed
        For j = 0 To UBound(Split(StrIn, vbCr)) - 1
          StrTmp Split(StrIn, vbCr)(j)
          .Text = Split(StrTmp, " - ")(0)
          .Execute Replace:=wdReplaceAll
          If .Found = True Then StrOut = StrOut & vbCr & StrTmp
        Next
      End With
      .InsertAfter StrOut
    End With
    Application.ScreenUpdating = True
    End Sub
    where 'Drive:\FilePath\Glossary.doc' is your document containing the glossary.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.excelforum.com/word-progr...ing-macro.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •