none
'Add to Dictionary' is disabled when using Custom Dictionaries with Word 2007 on Windows 2008 server. RRS feed

  • Question

  • I want to enable 'Add to Dictionary' programatically as it is disabled. Every time I have to launch and close Custom Dictionaries from Proofing Tools manually to enable 'Add to Dictionary'

    Thanks,

    Guru


    • Edited by BlueBangalore Tuesday, July 21, 2015 4:33 PM Rephrased with the actual problem.
    Friday, June 19, 2015 12:13 AM

Answers

  • I was able to fix the issue by adding below lines of code at the end. Not sure what's the logic behind this though.

    oDict.LanguageSpecific = True
    oDict.LanguageID = Word.WdLanguageID.wdEnglishUS
    

    Monday, June 22, 2015 3:02 PM
  • Here is the complete code.

    Sub RestoreDictionaries()
        Dim sDICFileName As String        'Dictionary File Name
        Dim sActiveCustomDictionary As String        'Active Dictionary Name
        Dim oCustDict As Dictionary        'Dictionary object

        On Error GoTo ErrHandler

        'Get the active dictionary name from a cerner logical
        sActiveCustomDictionary = Sys_GetLog("DTS_ActiveCustomDictionary")

        'Get the first dictionary name
        sDICFileName = Dir(m_sFull_Logical_Path & "\DIC" & "\*.DIC")

        If sDICFileName <> "" Then
            'If there are dictionaries in the backup folder then
            'clear all custom dictionaries in MS Word
           Call WordApp.CustomDictionaries.ClearAll
           
        End If

        Do While sDICFileName <> ""
            'Add Custom Dictionaries to MS Word list
            Set oCustDict = WordApp.Application.CustomDictionaries.Add(m_sFull_Logical_Path & "\DIC\" & sDICFileName)

            If sDICFileName = sActiveCustomDictionary Then
                'If the current dictionary is the active dictionary then set as active in MS Word
                WordApp.Application.CustomDictionaries.ActiveCustomDictionary = oCustDict
            End If

            sDICFileName = Dir
        Loop

       'FIX

        Dim CurrentLanguage As Long
        CurrentLanguage = WordApp.Language
        oCustDict.LanguageSpecific = True

        'Gets the language dynamically
        oCustDict.LanguageID = CurrentLanguage

        'Or set it English directly as below

        'oCustDict.LanguageID = wdEnglishUS

    Exit Sub

    • Marked as answer by BlueBangalore Tuesday, July 21, 2015 4:42 PM
    Tuesday, July 21, 2015 4:42 PM

All replies

  • Hi,

    Base on my test in word 2013, the dictionaries dialog doesn’t show.

    I would like to know what’s the requirement that you need to open the dialog window. Could you do it with Dictionaries object directly?

    # Dictionaries Object (Word)

    https://msdn.microsoft.com/en-us/library/office/ff194473.aspx?f=255&MSPPError=-2147217396

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 19, 2015 8:47 AM
    Moderator
  • Actual issue is the custom dictionary does not get activated when we launch Word programatically. If we type something and right click 'Add to Dictionary' is disabled.

    But if we go to Proofing tools -- > and open Custom Dictionaries dialog the required custom dictionary is checked. If we just close the dialog without making any changes and right click on the same text, 'Add to Dictionary' is activated. We don't see anything wrong with the code. Below is our code.

    Sub RestoreDictionaries()
        Dim sDICFileName As String        'Dictionary File Name
        Dim sActiveCustomDictionary As String        'Active Dictionary Name
        Dim oCustDict As Dictionary        'Dictionary object

        On Error GoTo ErrHandler

        'Get the active dictionary name from a cerner logical
        sActiveCustomDictionary = Sys_GetLog("DTS_ActiveCustomDictionary")

        'Get the first dictionary name
        sDICFileName = Dir(m_sFull_Logical_Path & "\DIC" & "\*.DIC")

        If sDICFileName <> "" Then
            'If there are dictionaries in the backup folder then
            'clear all custom dictionaries in MS Word
           Call WordApp.CustomDictionaries.ClearAll
           
        End If

        Do While sDICFileName <> ""
            'Add Custom Dictionaries to MS Word list
            Set oCustDict = WordApp.Application.CustomDictionaries.Add(m_sFull_Logical_Path & "\DIC\" & sDICFileName)

            If sDICFileName = sActiveCustomDictionary Then
                'If the current dictionary is the active dictionary then set as active in MS Word
                WordApp.Application.CustomDictionaries.ActiveCustomDictionary = oCustDict
            End If

            sDICFileName = Dir
        Loop

        Exit Sub


    Friday, June 19, 2015 1:40 PM
  • We have a Word based application which used COMAddin. We create custom dictionary based on the user login. We have an issue where in custom dictionary does not get activated when we launch Word programatically. If we type something and right click 'Add to Dictionary' is disabled.

    But when we debug the code we get the correct name for ActiveDictionary. All we have to do is Open and Close the Custom Dictionaries dialog (our dictionary is already in checked status) from Proofing Tools without making any change. If we right click on the text now the 'Add to Dictionary' is enabled.

    We want to have this activated first time when we launch the document and right click on a text. Below is the code. please look into this.

    Sub RestoreDictionaries()
        Dim sDICFileName As String        'Dictionary File Name
        Dim sActiveCustomDictionary As String        'Active Dictionary Name
        Dim oCustDict As Dictionary        'Dictionary object

        On Error GoTo ErrHandler

        'Get the active dictionary name from a cerner logical
        sActiveCustomDictionary = Sys_GetLog("DTS_ActiveCustomDictionary")

        'Get the first dictionary name
        sDICFileName = Dir(m_sFull_Logical_Path & "\DIC" & "\*.DIC")

        If sDICFileName <> "" Then
            'If there are dictionaries in the backup folder then
            'clear all custom dictionaries in MS Word
           Call WordApp.CustomDictionaries.ClearAll
           
        End If

        Do While sDICFileName <> ""
            'Add Custom Dictionaries to MS Word list
            Set oCustDict = WordApp.Application.CustomDictionaries.Add(m_sFull_Logical_Path & "\DIC\" & sDICFileName)

            If sDICFileName = sActiveCustomDictionary Then
                'If the current dictionary is the active dictionary then set as active in MS Word
                WordApp.Application.CustomDictionaries.ActiveCustomDictionary = oCustDict
            End If

            sDICFileName = Dir
        Loop

    Thanks


    Friday, June 19, 2015 1:49 PM
  • Mmm, I've never heard of anything like this, so there's no "known" cause that I'm aware of for the behavior you're seeing. It would help to have a set of exact steps to reproduce the behavior. The code snippet you provide isn't really enough.

    I do notice some oddities in the code you provide, however. If this is a COM Add-in, then I assume the language is VB.NET? Why do you use "Call" and "Set" in your code, then?

    Also, what's the purpose of WordApp.Application, as I'd assume "WordApp" is a Word.Application object?

    Since you're looping and re-assigning to the oCustDic object it might make a difference if you set oCustDic = Nothing at the end of every loop.


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, June 20, 2015 5:28 PM
    Moderator
  • Hi BlueBangalore

    When I check this command in VBA it tells me the comand is not available - so the Enum value is only present for purposes of backwards compatibility but is no longer available in newer versions of Word (probably starting with the "Riboon" versions in 2007). There is a Ribbon ControlId - Dictionary - but Word also doesn't seem to want to execute it as it gives an Automation Error when used with CommandBars.ExecuteMso

    As best I can tell, the custom dictionaries are managed in the Registry, although I don't know which keys are responsible for what you're trying to do, or whether the keys that controls the list is even "in the clear", or whether it's a binary encoded key. The folks in the Word IT Pro forum on the TechNet site might be able to tell you that. It's possible that changing the key information in the Registry will work more reliably for you than using Word's object model.


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, June 20, 2015 5:46 PM
    Moderator
  • Thanks Cindy for looking into this. I was able to fix the issue by adding below lines of code at the end. Not sure what's the logic behind this though.

    oDict.LanguageSpecific = True
    oDict.LanguageID = Word.WdLanguageID.wdEnglishUS</p><p>Thanks.
    


    Monday, June 22, 2015 3:01 PM
  • I was able to fix the issue by adding below lines of code at the end. Not sure what's the logic behind this though.

    oDict.LanguageSpecific = True
    oDict.LanguageID = Word.WdLanguageID.wdEnglishUS
    

    Monday, June 22, 2015 3:02 PM
  • Hi,

    Could you provide the complete code?

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 23, 2015 3:43 AM
    Moderator
  • Hi BlueBangalore

    Thanks for letting us know what helped :-)

    I think I knew the logic, once upon a time - now that you mention what works - but my memory is a bit vague. The folks in an end-user group (the Answers forum) might remember better <sigh> As best I can recall, when you use Word's Proofing Tools in the object model it's important to specify the language. At some point in time (years ago) Word became less "language independent" than it was, originally, and wanted custom dics to be set to a specific language...

    It's gotten so that, if you change the default language in Windows this will change the default language in Word and wipe out things Word considers language-dependent. And this has come to include Normal.dotm, with all the customizations, macros, etc. <sigh>


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, June 23, 2015 3:46 PM
    Moderator
  • Here is the complete code.

    Sub RestoreDictionaries()
        Dim sDICFileName As String        'Dictionary File Name
        Dim sActiveCustomDictionary As String        'Active Dictionary Name
        Dim oCustDict As Dictionary        'Dictionary object

        On Error GoTo ErrHandler

        'Get the active dictionary name from a cerner logical
        sActiveCustomDictionary = Sys_GetLog("DTS_ActiveCustomDictionary")

        'Get the first dictionary name
        sDICFileName = Dir(m_sFull_Logical_Path & "\DIC" & "\*.DIC")

        If sDICFileName <> "" Then
            'If there are dictionaries in the backup folder then
            'clear all custom dictionaries in MS Word
           Call WordApp.CustomDictionaries.ClearAll
           
        End If

        Do While sDICFileName <> ""
            'Add Custom Dictionaries to MS Word list
            Set oCustDict = WordApp.Application.CustomDictionaries.Add(m_sFull_Logical_Path & "\DIC\" & sDICFileName)

            If sDICFileName = sActiveCustomDictionary Then
                'If the current dictionary is the active dictionary then set as active in MS Word
                WordApp.Application.CustomDictionaries.ActiveCustomDictionary = oCustDict
            End If

            sDICFileName = Dir
        Loop

       'FIX

        Dim CurrentLanguage As Long
        CurrentLanguage = WordApp.Language
        oCustDict.LanguageSpecific = True

        'Gets the language dynamically
        oCustDict.LanguageID = CurrentLanguage

        'Or set it English directly as below

        'oCustDict.LanguageID = wdEnglishUS

    Exit Sub

    • Marked as answer by BlueBangalore Tuesday, July 21, 2015 4:42 PM
    Tuesday, July 21, 2015 4:42 PM