View Full Version : Main and Custom Dictionary
nazlan
03-05-2009, 05:55 PM
Can the spelling suggestion lists from word's main dictionary and custom dictionaries be differentiated upon mouse right click on wrong word spelling.
Help highly appreciated to answer this.
fumei
03-06-2009, 12:48 PM
Let me see if I understand.
If a word is deemed incorrectly spelled, and you right click, you want the listing of possible corrections to be marked as coming from either the main, or the custom, dictionary?
Sort of like:
wokred
Right-click:
worked (Main)
wokked (Custom)
nazlan
03-07-2009, 10:01 AM
Yes, that is basically what I am trying to do since I am incorporating many custom technical dictionaries. It would be helpful if the suggestion list can tell us which custom dictionary it comes from.
Your example is exactly like what I wan to implement.
 
worked (main)
wokked (custom)
 
or
 
worked
wokked (custom)
 
or if wokked is in a different color text.
 
Your help to point me to right direction is appreciated. I am new to VBA but I have used VB6 before.
 
Thanx.
fumei
03-09-2009, 01:51 PM
Sorry, but I do not think this is possible.  I could be wrong, and I do not have the time right now to dig as deep as possible to be 100% sure, but I do not think it possible.  I do not think Word distinquishes - or rather, I do not think the distinguishing is exposed to coding - between the dictionaries.
In other words, yes, Word does know if alternative spelling X comes from Main, and alternative spelling Y comes from Custom.  However, that discernment is not exposed.  It is all internal to Word.  Word simply displays ALL alternatives.  We can not get at it.
I think.
nazlan
03-09-2009, 06:29 PM
If we cannot get at it since it is all internal in word, can we disable the main dictionary and just use custom dictionary to do the spelling?
Removing the main spelling dictionary (lex file) ignores my "custom dictionary".
fumei
03-10-2009, 08:49 AM
You can make any Custom dictionary the default dictionary.
nazlan
03-10-2009, 11:22 PM
Yes, my "custom dictionary" is already the default dictionary. I thought one could disable or remove the main dictionary and just use the custom dictionary to spell check. Unfortunately, in my case it does not catch any misspelling.
Playing around with GetSpellingSuggestions I get the following below. Help to optimized the code is appreciated!!!!
 
-------------------------------------------------------------------
Sub DisplaySuggestions()
    Dim sugList As SpellingSuggestions
    Dim sugList1 As SpellingSuggestions
    Dim sug As SpellingSuggestion
    Dim sug1 As SpellingSuggestion
    Dim strSugList As String
    Dim strSugList1 As String
    Dim strSugListMalay As String
    
    Set sugList = GetSpellingSuggestions(Word:="tuliss", CustomDictionary2:="UTMWordList.dic", _
        SuggestionMode:=wdSpellword)
    Set sugList1 = GetSpellingSuggestions(Word:="tuliss", _
        SuggestionMode:=wdSpellword)
 
    If sugList.Count = 0 And sugList1.Count = 0 Then
        MsgBox "No suggestions."
        Else
            For Each sug In sugList
                strSugList = strSugList & vbTab & sug.Name & vbLf
            Next sug
            For Each sug1 In sugList1
                strSugList1 = strSugList1 & vbTab & sug1.Name & vbLf
                 
            Next sug1
    End If
    
MsgBox "The suggestions for this word are: " _
            & vbLf & strSugList & vbLf & strSugList1
End Sub
------------------------------------------------------
 
I get 
 
strSugList I get tulips, tulles, toils, tunis, tails, tiles
strSugList1 tulis, tulips
 
where "tulis" is in my custom dictionary.
 
How do I get another suggestion list where the strSugList1 is filtered by the strSugList to get a finalstrList with just tulis because tulips is already in strSugList. I hope this is clear where I want to do a duplicate removal for lists present in the first suggestion list.
 
Reason: Then I know that the entry "tulis" comes from my custom dictionary.
 
Thanks
fumei
03-11-2009, 09:19 AM
You are not (or should not be) getting :
tulips, tulles, toils, tunis, tails, tiles
Your code is:
strSugList = strSugList & vbTab & sug.Name & vbLf
I see no comma in there. I see a Tab.  In any case, I think brute force is what it ias going to take.
sugList is a collection.  Each item has an index number.
sugList1 is also a collection.  Each item has an index number.
You already realize that both have a .Count.
So....compare them one by one, and if they match, delete that item (as a string) from strSugList.  Somewhat like:
' declare variants
Dim var
Dim var2
' looping through each item
For var = 0 To sugList1.Count
' check each item
For var2 = 0 to sugList1.Count  
' if there is a match, replace that piece of the string 
If sugList(var) = sugList1(var2) Then
      strSugList = Replace(strSugList, sugList(var).Name, _
         "")
nazlan
03-11-2009, 11:32 PM
In order to save space in here I wrote the output as comma deliminited.
vbTab used to indent the output in the messagebox.
How do I implement your vba example to the my code. Getting error "The requested number of collection does not exist" for sugList1(var2)
 
Do I have to reloop again in order to remove the duplicates?
I am not able to filter out the "tulips" in strSugList1 using the given example.
Help.....
Thank you in advance for help.
fumei
03-12-2009, 09:28 AM
Post the entire code.
nazlan
03-12-2009, 06:05 PM
Here is the code based on the previous post and modification based on your recommendation. The code is not optimized and slow, help to improve is appreciated.
 
--------------------------------------
Sub DisplaySuggestions()
    Dim sugList As SpellingSuggestions
    Dim sugList1 As SpellingSuggestions
    Dim sug As SpellingSuggestion
    Dim sug1 As SpellingSuggestion
    Dim strSugList As String
    Dim strSugList1 As String
    Dim var
    Dim var1
    
    Set sugList = GetSpellingSuggestions(Word:="tuliss", CustomDictionary2:="UTMWordList.dic", _
        SuggestionMode:=wdSpellword)
    Set sugList1 = GetSpellingSuggestions(Word:="tuliss", _
        SuggestionMode:=wdSpellword)
 
    If sugList.Count = 0 Then
        MsgBox "No suggestions."
    ElseIf sugList1.Count = 0 Then
        MsgBox "No suggestions."
    Else
    For Each sug1 In sugList1
            strSugList1 = strSugList1 & vbTab & sug1.Name & vbLf
        For Each sug In sugList
             If sug1.Name = sug.Name Then
             strSugList1 = Replace(strSugList1, sug.Name, "")
             End If
             Next sug
    Next sug1
    End If
    MsgBox "this is what i get from my custom dictionary" _
    & vbLf & strSugList1
End Sub
-------------------------------------------
At the moment I don't get any error but will try and test with other word lists to try and see the effectiveness of just getting suggestion list from custom dictionaries. Indirectly we can then differentiate between lists from main and custom dictionary.
 
The VBA code for above will depend on how many spellingsuggestionlist and the for next loop I am using is not efficient. The above based on my example goes through loop twice (tulis and tulips) I think since if we check the strSugList will give repeating suggestion twice (tulips, tulles......tulips,tulles...)
 
Please comment on code used. Thank you.
nazlan
03-15-2009, 08:48 PM
Anybody can help to optimized or make the code faster? Most of the time spelling suggestions from custom dictionary will only give single suggestions, hence there is no need to check for duplicate.
 
The Dim var and Dim var1 can be removed.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.