473,439 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,439 software developers and data experts.

Create a list box of synonyms from word.application?

Is there a way to use word.application to pull synonyms from the word thesaurus and have them appear in a list box? I know how to bring up the thesaurus box using word.application, but I don't know how to extract that data to appear in Access. I've searched the web on this topic and found surprisingly little about it.

If this isn't possible, I'd be interested in knowing any other methods of integrating a thesaurus into an Access 2007 database.

Thanks,
Adam
Nov 12 '09 #1

✓ answered by ADezii

  1. The following Sub-Routine, using Automation with Microsoft Word, will generate a list of Synonyms for the Word passed to it:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub ReturnSynonyms(strWord As String)
    2. Dim aList As Variant
    3. Dim intCounter As Integer
    4.  
    5. Dim wd As Word.Application
    6.  
    7. Set wd = New Word.Application
    8.  
    9. Debug.Print "Synonyms for " & strWord
    10. Debug.Print "---------------------------"
    11.  
    12. aList = wd.SynonymInfo(Word:=strWord, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
    13.  
    14. If UBound(aList) <> 0 Then
    15.   For intCounter = 1 To UBound(aList)
    16.     Debug.Print aList(intCounter)
    17.   Next
    18. Else
    19.   MsgBox "No Synonyms found for " & strWord, vbExclamation, "No Synonyms Found"
    20. End If
    21.  
    22. Set wd = Nothing
    23. End Sub
  2. Sample Call to Routine:
    Expand|Select|Wrap|Line Numbers
    1. Call ReturnSynonyms("old")
  3. Sample OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. Synonyms for old
    2. ---------------------------
    3. aged
    4. elderly
    5. older
    6. mature
    7. getting on
    8. not getting any younger

26 10254
ADezii
8,834 Expert 8TB
  1. The following Sub-Routine, using Automation with Microsoft Word, will generate a list of Synonyms for the Word passed to it:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub ReturnSynonyms(strWord As String)
    2. Dim aList As Variant
    3. Dim intCounter As Integer
    4.  
    5. Dim wd As Word.Application
    6.  
    7. Set wd = New Word.Application
    8.  
    9. Debug.Print "Synonyms for " & strWord
    10. Debug.Print "---------------------------"
    11.  
    12. aList = wd.SynonymInfo(Word:=strWord, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
    13.  
    14. If UBound(aList) <> 0 Then
    15.   For intCounter = 1 To UBound(aList)
    16.     Debug.Print aList(intCounter)
    17.   Next
    18. Else
    19.   MsgBox "No Synonyms found for " & strWord, vbExclamation, "No Synonyms Found"
    20. End If
    21.  
    22. Set wd = Nothing
    23. End Sub
  2. Sample Call to Routine:
    Expand|Select|Wrap|Line Numbers
    1. Call ReturnSynonyms("old")
  3. Sample OUTPUT:
    Expand|Select|Wrap|Line Numbers
    1. Synonyms for old
    2. ---------------------------
    3. aged
    4. elderly
    5. older
    6. mature
    7. getting on
    8. not getting any younger
Nov 12 '09 #2
ADezii - That's positively outstanding! I'll test it out today.
Thanks,
Adam
Nov 13 '09 #3
ADezii
8,834 Expert 8TB
@AdamOnAccess
I've intentionally made the call very flexible in that there are a variety of Methods to return the Synonyms, e.g. populate a List Box, Function returning an Array, on a single line delimited by a comma, etc.

P.S. - You can also return Antonyms.
Nov 13 '09 #4
MMcCarthy
14,534 Expert Mod 8TB
That's the words for our ADezii, "positively outstanding". We've very lucky to have him :)

Mary
Nov 13 '09 #5
ADezii
8,834 Expert 8TB
@msquared
Thanks Mary for the kind words, but I feel very honored just being a part of this elite group and excellent Forum. I've learned just as much as I have taught.
Nov 13 '09 #6
NeoPa
32,556 Expert Mod 16PB
@AdamOnAccess
Adam - That's positively typical!

Great work again ADezii :)

Just a quick question though :
Is there any reason why you start at 1 on line #15 of your code. I would expect LBound(aList) to resolve to 0 generally.
Nov 15 '09 #7
ADezii
8,834 Expert 8TB
@NeoPa
The SynonymList Property of the SynonymInfo Object returns a Variant Array of Strings that apparently is 1-based as evidenced by the modified code below which used LBound() instead of 1 and still produces the same results (LBound(aList) resolves to 1).
Expand|Select|Wrap|Line Numbers
  1. 'Relevant code only has been posted
  2. aList = wd.SynonymInfo(Word:=strWord, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
  3.  
  4. If UBound(aList) <> 0 Then
  5.   For intCounter = LBound(aList) To UBound(aList)
  6.     Debug.Print aList(intCounter)
  7.   Next
  8. Else
  9.   MsgBox "No Synonyms found for " & strWord, vbExclamation, "No Synonyms Found"
  10. End If
P.S. - Thanks for the kind words.
Nov 15 '09 #8
NeoPa
32,556 Expert Mod 16PB
Oh. That's cool then :)
Nov 15 '09 #9
Hi ADezii,

I've been working with the code you posted and for the most part, it works great. I have run across one issue that I can't seem to fix. Here is the function I'm using:

Expand|Select|Wrap|Line Numbers
  1. Public Function pfnGetSynonyms(strWord As String) As Variant
  2. 'Returns an array of Synonyms words
  3. 'Requires refererence to Microsoft Word 10.0 Object Library
  4.  
  5.    Dim astrSynonyms As Variant
  6.  
  7.    Dim wd As Word.Application
  8.  
  9.    Set wd = New Word.Application
  10.  
  11.    astrSynonyms = wd.SynonymInfo(Word:=strWord, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
  12.  
  13.    If LBound(astrSynonyms) <> 0 Then
  14.       pfnGetSynonyms = pfnRenumberArray(astrSynonyms)
  15.    Else
  16.       pfnGetSynonyms = astrSynonyms
  17.    End If
  18.  
  19.    Set wd = Nothing
  20.  
  21. End Function
  22.  
Recently, I sent the word "brewery" to the function and it errored:

Run-Time Error 5843
One of the values passed to this method or property is out of range.

Error occured on this line:
astrSynonyms = wd.SynonymInfo(Word:=strWord, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)

I went into MS Word and ran the thesaurus on "brewery" and it came back with no suggestions. I also tested the work "brewing". It also failed and MS Word thesaurus also had no suggestions.

So it appears that, when you submit a word and the thesaurus can't offer any suggestions, the above line in the code errors before it reaches the test to see if the returned array is empty.

Would you know how to fix that?
Thanks,
Adam
Nov 29 '09 #10
ADezii
8,834 Expert 8TB
You can set a 'Trap' for that specific Error (5843), then display a descriptive Message Box indicating to the User that no Matches were found:
Expand|Select|Wrap|Line Numbers
  1. Public Function pfnGetSynonyms(strWord As String) As Variant
  2. On Error GoTo Err_pfnGetSynonyms
  3. 'Returns an array of Synonyms words
  4. 'Requires refererence to Microsoft Word 10.0 Object Library
  5. Dim astrSynonyms As Variant
  6. Dim wd As Word.Application
  7.  
  8. Set wd = New Word.Application
  9.  
  10. astrSynonyms = wd.SynonymInfo(Word:=strWord, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
  11.  
  12. If LBound(astrSynonyms) <> 0 Then
  13.   pfnGetSynonyms = pfnRenumberArray(astrSynonyms)
  14. Else
  15.   pfnGetSynonyms = astrSynonyms
  16. End If
  17.  
  18. Set wd = Nothing
  19.  
  20. Exit_pfnGetSynonyms:
  21.   Exit Function
  22.  
  23. Err_pfnGetSynonyms:
  24.   If Err.Number = 5843 Then
  25.     MsgBox "No Synonyms were found for [" & strWord & "]", vbExclamation, _
  26.     "No Matches Found"
  27.   Else
  28.     MsgBox Err.Description, vbExclamation, "Error in pfnGetSynonyms()"
  29.   End If
  30.     Resume Exit_pfnGetSynonyms
  31. End Function
P.S. - Take a specific look at Code Lines: 2, 20 - 21, and 23 - 30.
Nov 29 '09 #11
Neat! Thanks ADezii!
Nov 29 '09 #12
ADezii
8,834 Expert 8TB
You are quite welcome.
Nov 29 '09 #13
Hi again ADezii,

I hope you don't mind me hitting you up again about this piece of code, but frankly, I think it is the coolest thing. It's very useful for my application.

I've set up a text box where a user can enter a phrase. I use the split function to break that phrase into individual words, then I run each word through the thesauraus. I then take each list from the thesaurus and combine them to form lists of synonoums phrases.

It's working great except for one issue: I am running out of virtual memory after I use it a few times. After a few runs, I have to reboot. Is there anything I can do to fix this?

Thanks,
Adam
Nov 29 '09 #14
ADezii
8,834 Expert 8TB
  1. Kindly post all relevant code that you have not already posted, or better yet, Upload a Test Version of the Database.
  2. If you are not going to Upload the Database, I'll need to see the code behind pfnRenumberArray(astrSynonyms) as well.
Nov 30 '09 #15
NeoPa
32,556 Expert Mod 16PB
Adam,

FYI.There are two main things to look out for in a situation like this (ADezii knows already) :
  1. All objects must be properly closed and released in the code.
  2. The structure or flow of the code, is such that it works as efficiently as possible. Sometimes it's quite possible to reuse an object. It's often easier to create new objects for each task though. This is rarely an issue with straight-through programming, but anything repetitive or recursive multiplies this effect so that it can be a problem.
Anyway, I'm sure ADezii will be able to find (& fix) it for you.
Nov 30 '09 #16
ADezii,

I'll put together a database that contains all the relevent stuff. It is currently in Access 2007. Is that version OK, or do you need something earlier?

NeoPa,
Thanks for the input. Yes, I suspect I am not closing or releasing something, or perhaps I am creating multiple instances.

Or perhaps my machine has issues. Either way, I'll get a version uploaded and let you guys take a whack at it.

Thanks,
Adam
Nov 30 '09 #17
ADezii
8,834 Expert 8TB
I'll put together a database that contains all the relevent stuff. It is currently in Access 2007. Is that version OK, or do you need something earlier?
For the time being, I'll need it in an Access 2002 Version.
Nov 30 '09 #18
NeoPa
32,556 Expert Mod 16PB
Adam,

I knocked something up before as a guide to attaching databases. I hope it helps.
When attaching your work please follow the following steps first :
  1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
  2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
  3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
  4. If you've done anything in steps 1 to 3 then make sure that the problem you're experiencing is still evident in the updated version.
  5. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
  6. Compact the database.
  7. Compress the database into a ZIP file.
  8. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.
It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.
Nov 30 '09 #19
ADezii,

Ok, attached is an access 2002 version of a database containing the code we've been discussing. I've narrowed it down to only the relevent parts. Please don't think I'm being cagey about my code; I have no doubt you can write circles around any code I've ever written, but there are a few other bugs I have to work out and I didn't want them muddying the waters. I'd be happy to show you the entire project if you find it interesting - just let me know.

NeoPa, same goes for you too.

I have tested the code in this 2002 version and I have it working exactly as it works in the 2007 version. I've added plenty of comments.

Again, the objective is to take a phrase like "Beer Making Kit", and return a list of synonyms phrases like "Beer Manufacturing Equipment", "Beer Producing Gear", etc.

To run it, just open the only form in the database, enter a phrase like "Beer Making Kit", and hit the button. After a few moments, the list box should fill up with phrases.

Right now, it works nearly perfectly, except that after it runs a few times I begin to get warnings that virtual memory is tapping out.

Good luck with it and try not to laugh at my coding too much :)
Thanks,
-Adam
Attached Files
File Type: zip theasurusPhrases.zip (34.5 KB, 205 views)
Nov 30 '09 #20
ADezii
8,834 Expert 8TB
Got it, give me a couple of days to go over the code.
Nov 30 '09 #21
ADezii
8,834 Expert 8TB
Before you do anything else, try to reclaim the Memory used by the Arrays in each Procedure, as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdGetLikePhrases_Click()
  2.  ...'ALL previous code intentionally omitted
  3.  
  4. 'Reclaim/Free the Memory used by the Arrays
  5. Erase astrSynonyms
  6. Erase astrNewList
  7. Erase astrMultiSynonyms
  8. End Sub
Dec 1 '09 #22
Ok. I'll run a few tests and see how that goes.
Thanks,
-Adam
Dec 1 '09 #23
ADezii,

Chalk up another victory for you!

The virtual memory problem is gone. After some minor debugging, the program performs perfectly.

Just out of curiousity, how long does it take to become an Access phenom like you?

Thanks again,
-Adam
Dec 1 '09 #24
ADezii
8,834 Expert 8TB
Just a self taught home boy!
Dec 1 '09 #25
Dear all,
Is there any possibility to add a new synonyms list to MS-word or customize it?

I have a list of synonyms which is not already in the list.
Jun 26 '10 #26
ADezii
8,834 Expert 8TB
@alphanj
Hello alphani. This was quite a challenge, since I do believe that you cannot modify the intrinsic Synonym List in Microsoft Work for any given word(s). I did, however, create a Custom Function which will supplement Word's Synonym List for a specific word. Pass to the Function the word for which you want to generate Synonyms, as well as an Optional, Comma-Delimiter String consisting of additional Synonyms for the given word separated by Comma(s). Enough already, I post the code along with sample usage. Any questions, feel free to ask.
  1. Standard Synonym List for 'Devil' and results via Function Call:
    Expand|Select|Wrap|Line Numbers
    1. ? fReturnSynonyms("Devil")
    Expand|Select|Wrap|Line Numbers
    1. Synonyms for Devil
    2. ---------------------------
    3. fiend
    4. evil spirit
    5. imp
    6. mischievous sprite
    7. sprite
  2. Let's add NeoPa and ADezii as additional Synonyms for 'Devil':
    Expand|Select|Wrap|Line Numbers
    1. ? fReturnSynonyms("Devil","NeoPa,ADezii")
    Expand|Select|Wrap|Line Numbers
    1. Synonyms for Devil
    2. ---------------------------
    3. fiend
    4. evil spirit
    5. imp
    6. mischievous sprite
    7. sprite
    8. NeoPa
    9. ADezii
  3. Code that makes this all happen:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fReturnSynonyms(strWord As String, Optional strMoreArgs As String = "")
    2. On Error GoTo Err_fReturnSynonyms
    3. Dim aList As Variant
    4. Dim intCounter As Integer
    5. Dim varRet As Variant
    6. Dim intCounter_2 As Integer
    7.  
    8. Dim wd As Word.Application
    9.  
    10. Set wd = New Word.Application
    11.  
    12. aList = wd.SynonymInfo(Word:=strWord, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
    13.  
    14. Debug.Print "Synonyms for " & strWord
    15. Debug.Print "---------------------------"
    16.  
    17. If strMoreArgs <> "" Then
    18.   varRet = Split(strMoreArgs, ",")
    19.     For intCounter = LBound(varRet) To UBound(varRet)
    20.       'MsgBox varRet(intCounter)
    21.       ReDim Preserve aList(UBound(aList) + 1)
    22.       aList(UBound(aList) - 1) = varRet(intCounter)
    23.     Next
    24. End If
    25.  
    26. If UBound(aList) <> 0 Then
    27.   For intCounter_2 = LBound(aList) To UBound(aList)
    28.   'For intCounter_2 = 0 To UBound(aList) - 1
    29.     Debug.Print aList(intCounter_2)
    30.   Next
    31. End If
    32.  
    33. Set wd = Nothing
    34.  
    35. Erase aList
    36.  
    37. Exit_fReturnSynonyms:
    38.   Exit Function
    39.  
    40. Err_fReturnSynonyms:
    41.   If Err.Number = 5843 Then
    42.     MsgBox "No Synonyms found for " & strWord, vbExclamation, "No Synonyms Found"
    43.   Else
    44.     MsgBox Err.Description, vbExclamation, "Error in fReturnSynonyms()"
    45.   End If
    46.     Resume Exit_fReturnSynonyms
    47. End Function
    48.  
    49.  
  4. P.S. - Modifications were made to the original Code Template.
Jun 26 '10 #27

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: picknicker187 | last post by:
hi, the following while function(it´s supposed to find word synonyms out of a list) always quits after running through the list in the inner loop once. it´s like the aktuell = aktuell->next on...
7
by: Daniel Walzenbach | last post by:
Hello, I want to create a Word XML file based on the input users make in a VB.NET application. I imagine creating a template in Word and saving it as a XML file. I then want to fill the...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
65
by: Steven Watanabe | last post by:
I know that the standard idioms for clearing a list are: (1) mylist = (2) del mylist I guess I'm not in the "slicing frame of mind", as someone put it, but can someone explain what the...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
2
by: Zethex | last post by:
At the moment i'm doing a piece of work for school and I'm stuck at the moment. I have a list of words, for example: Sentence = I have another list which I need to use to replace certain...
0
by: dbsog7777 | last post by:
I was trying to use the sample code below, but I encountered two errors: Application.DoEvents() and AutoText(entry). I am not sure how to correct the errors. I trying to use the sample code to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.