+ Reply to Thread
Results 1 to 24 of 24

Glossary Generating Macro

  1. #1
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Lightbulb Glossary Generating Macro

    Edit: Please see post#9 for more clear explanation


    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.


    Please Login or Register  to view this content.



    Edit: I also posted this here:

    http://www.vbaexpress.com/forum/showthread.php?t=51068


    However I am not following that as that website is mostly down. Have not posted it anywhere else.
    Last edited by dexterousy; 11-04-2014 at 12:32 AM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Glossary Generating Macro

    I'm sure Word VBA experts will be aghast at my code, but it worked for me

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 10-30-2014 at 12:12 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Glossary Generating Macro

    Cross-posted at: http://www.vbaexpress.com/forum/show...ing-Macro-Help
    For cross-posting etiquette, please read FORUM RULE 8: http://www.excelforum.com/forum-rule...rum-rules.html
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Glossary Generating Macro

    Thanks to macropod for pointing this out and providing the link. I will emphasize that we have an actual rule about this:

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    Thank you for letting me know. I have updated the OP.

    Quote Originally Posted by macropod View Post
    Cross-posted at: http://www.vbaexpress.com/forum/show...ing-Macro-Help
    For cross-posting etiquette, please read FORUM RULE 8: http://www.excelforum.com/forum-rule...rum-rules.html
    Quote Originally Posted by 6StringJazzer View Post
    Thanks to macropod for pointing this out and providing the link. I will emphasize that we have an actual rule about this:

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  6. #6
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    Thank you very much Bernie, but I have more than 5 items for some of the words/phrases. I should also clarify that the list above is just an example, the actual list is longer and comprises of phrases and sentences, along with just words. Also, I would like the output like this:

    Word 1 - suggestion 1, suggestion 2, ...... suggestion n
    word 5 - suggestion 1, suggestion 2, ...... suggestion n
    .
    .
    word n - suggestion 1, suggestion 2, ...... suggestion n

    And all the words identified from the list should be highlighted in document as well and suggestions should be summarized at the bottom.



    Quote Originally Posted by Bernie Deitrick View Post
    I'm sure Word VBA experts will be aghast at my code, but it worked for me

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    Also, I received the following response from link posted in post#1. However, this does not work as I will be sending this to other users who may or may not have a separate file. Also, I don't know how to use another word file in this.

    Please let me know if you have any other suggestions than mentioned in this post


    Please Login or Register  to view this content.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Glossary Generating Macro

    Quote Originally Posted by dexterousy View Post
    Also, I received the following response from link posted in post#1. However, this does not work as I will be sending this to other users who may or may not have a separate file. Also, I don't know how to use another word file in this.
    It would be helpful if you actually specified you needs at the outset, rather that having people waste time working on the matter only to find out after the event you haven't bothered to include something you regard as important. If the entries aren't in a file someone can edit, how is anyone except a programmer supposed to maintain the list? Besides which, why wouldn't the other users have a separate glossary file? Surely, if you intend them to use a particular glossary, you could send them that with the macro...

  9. #9
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    Quote Originally Posted by macropod View Post
    It would be helpful if you actually specified you needs at the outset, rather that having people waste time working on the matter only to find out after the event you haven't bothered to include something you regard as important. If the entries aren't in a file someone can edit, how is anyone except a programmer supposed to maintain the list? Besides which, why wouldn't the other users have a separate glossary file? Surely, if you intend them to use a particular glossary, you could send them that with the macro...
    Sorry, I indicated I am new at this. I did not know that it will be important for the query.
    Yes I would prefer to have it in the macro itself rather than having a separate file. I have the data in a word file and it is sent to users. However, the macro is supposed to eliminate the use of the file and do the "search and suggest" for them. Below is a screenshot of some of the items.

    http://oi61.tinypic.com/29kzajq.jpg

    Summary for those who cannot see the link:

    Words: Ensure, guarantee, satisfy
    Suggestions: Support, facilitate, advise, assist, assess
    Words: Maximize, optimize, minimize
    Suggestions: Increase, improve, decrease, reduce



    Here is what I think we can do (atleast thats what I would have done in C++)

    Create a 2D array with n rows. The first few elements in Array based on list above can be

    [1,1] = ["ensure", "Support, facilitate, advise, assist, assess"]
    [2,1] = ["guarantee", "Support, facilitate, advise, assist, assess"]
    [3,1] = ["satisfy", "Support, facilitate, advise, assist, assess"]
    and so on


    And once the macro runs, it looks for the words in first row and if it is in the document, it gets highlighted and both the word and the suggestions are posted at the end of the document.



    So for example, if a document has ensure, satisfy and maximize in it. then those words will be highlighted in the document and the following will be displayed at the bottom of the document:

    Ensure : Support, facilitate, advise, assist, assess
    Satisfy: Support, facilitate, advise, assist, assess
    Maximize: Increase, improve, decrease, reduce

    and so on.


    Hope this helps!

    Thank you for the help so far.
    Attached Images Attached Images

  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Glossary Generating Macro

    Try:
    Please Login or Register  to view this content.
    Although not strictly necessary, each glossary entry is on a separate line.

  11. #11
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    That does work but only for the first instance. So whatever word/phrase it finds first it is highlighted and then it does create a line at the bottom, but no other words are picked up.


    Quote Originally Posted by macropod View Post
    Try:
    Please Login or Register  to view this content.
    Although not strictly necessary, each glossary entry is on a separate line.

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Glossary Generating Macro

    Try it like this:

    Please Login or Register  to view this content.

  13. #13
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Glossary Generating Macro

    Quote Originally Posted by dexterousy View Post
    That does work but only for the first instance. So whatever word/phrase it finds first it is highlighted and then it does create a line at the bottom, but no other words are picked up.
    All terms in the array are highlighted and reported if found in the document when I run the macro ...

    That said, you could try adding:
    .Wrap = wdFindContinue
    before:
    For i = 0 To UBound(ArrTerms)
    This will ensure a parameter like wdFindStop from a previous Find/Replace operation doesn't compromise the outcome.
    Last edited by macropod; 11-06-2014 at 03:43 AM.

  14. #14
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    That did work, but when I try to add all the items (words/sentences), it gives this error:

    "Too many line continuations"



    Quote Originally Posted by Bernie Deitrick View Post
    Try it like this:

    Please Login or Register  to view this content.

  15. #15
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Glossary Generating Macro

    You cannot have than 24 consecutive line-continuation characters. As I said in post #10, they aren't necessary anyway. You could, for example, use:
    ArrTerms() = Array("Paper - report, transcript, summary", "Financial documents - balance-sheet, income statement, forecast, budget", "Expert - professional, teacher, experienced", _
    "Term4 - expression1, expression2", "Term5 - expression1, expression2, expression3, expression4", "Term6 - expression1, expression2")
    That alone would treble the # of terms. Other approaches are also possible. Of course, if you kept the terms in a separate document, as previously suggested, you wouldn't have these issues...

  16. #16
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Glossary Generating Macro

    Change to this style to do away with the continuations.

    If you have, say, 100 terms:

    Dim ArrTerms(1 To 100) As String
    ArrTerms(1) = "Paper - report, transcript, summary"
    ArrTerms(2)= "Financial documents - balance-sheet, income statement, forecast, budget"
    ArrTerms(3) = "Expert - professional, teacher, experienced"
    .....
    ArrTerms(100) = "Excel VBA - Hard to use, Need lots of experience"

    and change

    For i = 0 To UBound(ArrTerms)

    to

    For i = 1 To 100

  17. #17
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    Thank you for the help!
    I get the following error - Run-time error '9'
    Subscript out of range

    Here is what I have:



    Sub CompileDocumentGlossary2()
    Application.ScreenUpdating = False
    Dim ArrTerms(1 To 45) As String, StrTmp As String, StrOut As String, i As Long
    ArrTerms(1) = "Audit - Comment on, analyse, study, read"
    ArrTerms(2) = "Review - Comment on, analyse, study, read"
    ArrTerms(3) = "Compile - Comment on, analyse, study, read"
    .
    ..
    ...


    to ArrTerms(44) = "........."



    For i = 0 To 45
    With ActiveDocument.Range
    With .Find
    .MatchWholeWord = True
    .MatchCase = False
    .Replacement.Highlight = True
    StrTmp = ArrTerms(i)
    .Text = Split(StrTmp, " - ")(0)
    .Execute Replace:=wdReplaceAll

    If .Found = True Then StrOut = StrOut & vbCr & ArrTerms(i)
    End With
    End With
    Next i

    ActiveDocument.Range.InsertAfter StrOut

    Application.ScreenUpdating = True
    End Sub





    Quote Originally Posted by Bernie Deitrick View Post
    Change to this style to do away with the continuations.

    If you have, say, 100 terms:

    Dim ArrTerms(1 To 100) As String
    ArrTerms(1) = "Paper - report, transcript, summary"
    ArrTerms(2)= "Financial documents - balance-sheet, income statement, forecast, budget"
    ArrTerms(3) = "Expert - professional, teacher, experienced"
    .....
    ArrTerms(100) = "Excel VBA - Hard to use, Need lots of experience"

    and change

    For i = 0 To UBound(ArrTerms)

    to

    For i = 1 To 100

  18. #18
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Glossary Generating Macro

    You can't use terms like:
    ArrTerms(44) = "........."
    All of the terms you use must be populated as per terms 1 - 3 and the 45 in:
    For i = 0 To 45
    cannot exceed the highest array element. A simpler way of ensuring that is to use:
    For i = 1 To UBound(ArrTerms)
    There is no need to hard-code the number here as Bernie seems to suggest in post #16
    Last edited by macropod; 11-13-2014 at 04:38 AM.

  19. #19
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    Yes, I updated all the terms. i just didnt paste it as it is lot of data.

    I updated to "for i = 0 to Ubound(Arrterms)"

    However, I am still getting the same error and when I hit Debug, it takes me to the following line:

    StrTmp = ArrTerms(i)


    Quote Originally Posted by macropod View Post
    You can't use terms like:
    ArrTerms(44) = "........."
    All of the terms you use must be populated as per terms 1 - 3 and the 45 in:
    For i = 0 To 45
    cannot exceed the highest array element. A simpler way of ensuring that is to use:
    For i = 1 To UBound(ArrTerms)
    There is no need to hard-code the number here as Bernie seems to suggest in post #16

  20. #20
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Glossary Generating Macro

    Quote Originally Posted by dexterousy View Post
    Yes, I updated all the terms. i just didnt paste it as it is lot of data.

    I updated to "for i = 0 to Ubound(Arrterms)"
    But that isn't the same as I posted...
    You also need to make sure you don't declare more array elements than you use. You have:
    Dim ArrTerms(1 To 45) As String
    but, if you only use 1-44, the last element will be empty and will therefore throw the error.

  21. #21
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Glossary Generating Macro

    Sorry - I was brain-dead:

    For i = 0 To UBound(ArrTerms)

    should have been

    For i = 1 To UBound(ArrTerms)

    so change

    For i = 0 To 45

    to

    For i = 1 To 45

  22. #22
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    Thank you that worked. The only little bug remaining is that it is using the last used colour to highlight instead of Yellow.

    Quote Originally Posted by Bernie Deitrick View Post
    Sorry - I was brain-dead:

    For i = 0 To UBound(ArrTerms)

    should have been

    For i = 1 To UBound(ArrTerms)

    so change

    For i = 0 To 45

    to

    For i = 1 To 45

  23. #23
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: Glossary Generating Macro

    We had the line

    Options.DefaultHighlightColorIndex = wdYellow

    Did you not include that?
    Last edited by Bernie Deitrick; 11-13-2014 at 11:22 AM.

  24. #24
    Registered User
    Join Date
    10-29-2014
    Location
    Vancouver, Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: Glossary Generating Macro

    It worked! Thank you very much for all your help and patience!


    Quote Originally Posted by Bernie Deitrick View Post
    We had the line

    Options.DefaultHighlightColorIndex = wdYellow

    Did you not include that?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Merging duplicates in a glossary
    By greek in forum Excel Programming / VBA / Macros
    Replies: 30
    Last Post: 03-31-2014, 06:27 AM
  2. [SOLVED] Replacements on 2 column glossary
    By greek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2013, 02:13 AM
  3. Excel glossary?!
    By krtsbgfut in forum Excel General
    Replies: 1
    Last Post: 02-05-2013, 11:19 AM
  4. creating a glossary
    By cynthia74 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-17-2009, 07:09 AM
  5. Hyperlinking to a Glossary
    By AndrewB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2006, 09:19 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1