Auto-add to custom dictionaries on right-click?

I work as a medical transcriptionist. What I would LIKE to do is be able to right-click on things like patient's names (they recur regularly) and product brand names (ShearBan, Kerlix, and so on) and have them saved to a custom dictionary (say, MyPatientNames, and MyMTProducts) or something -- and then, when I right click on them because they're not in the default dictionary, have the option to save them to the custom dictionaries and NOT to the default dictionary. 

Will Word do this? The how-to videos I have watched seem to indicate that to get the words in custom dictionaries, you have to know the whole list you want recognized FIRST -- then you type those in and the specialized dictionary recognizes them. But I don't get given lists of patient names -- if they are unusual, they are spelled out when the notes are dictated, not given to me beforehand as a text list to refer to. (It would be nice if the companies would do this, but they don't.)  I also don't get lists of product brand names that pop up in the transcriptions either.  

Ergo, what I'd like to do is be able to simply right click on the patient name or product name and have it be saved in the custom dictionary. Can Word be configured to do this? Or perhaps someone has created an add-on to take care of this? 

If it CAN'T do this,  where can I go to suggest this as a product improvement for the next release? 

Thanks!
TwinOwl (hoot hoot)

Answer
Answer
You CAN do this, with some custom macro programming. All is provided below -- you'll just have to follow the instructions at http://www.gmayor.com/installing_macro.htm to do some copy/paste into the proper location.

There are three parts to the solution. The first part is to put into place three macros involved in actually adding the selected word to one of the two dictionaries. The second part is to put in a macro that will add the desired entries to the right-click menu (because there is no other way to modify that menu in Word 2007 or 2010). The third part is to use the Options > Proofing > Custom Dictionaries dialog to create the two dictionaries and add them to the dictionaries collection, if they aren't already there.

The first part:
Use the instructions in the "Modules" section of the installing_macro.htm page to create a module in your Normal template and name it ContextMacros. (This will be important in the second part.) Then copy the following code and paste it into the ContextMacros module.

Sub AddToMyPatientNames()
    Dim dicFile As String
   
    dicFile = "MyPatientNames.dic"
    AddToCustomDictionary dicFile
End Sub

Sub AddToMyMTProducts()
    Dim dicFile As String
   
    dicFile = "MyMTProducts.dic"
    AddToCustomDictionary dicFile
End Sub

(edit) IMPORTANT: This part of the code, up to the "STOP HERE", is incorrect. Replace it with the code from my later reply.

Private Sub AddToCustomDictionary(dicFile As String)
    Dim thisDict As Dictionary
    Dim testStr As String
    Dim newWord As String
    Dim rg As Range

    On Error GoTo errhdl
   
    newWord = Selection.Words(1).SpellingErrors(1).Text
   
    'Get the path to the custom dictionary
    Set thisDict = CustomDictionaries(dicFile)
    dicFile = thisDict.Path & "\" & dicFile
   
    'Check for existence of file
    testStr = Dir(dicFile)
    If Len(testStr) = 0 Then
        Open dicFile For Output As #1
    Else
        Open dicFile For Append As #1
    End If
   
    Print #1, newWord
    Close #1
   
    'Turn off spelling wavy underlines for this word
    Set rg = ActiveDocument.Range
    With rg.Find
        While .Execute(FindText:=newWord, Wrap:=wdFindStop)
            rg.SpellingChecked = True
        Wend
    End With
   
    Exit Sub
   
errhdl:
    If Err.Number = 5941 Then
        MsgBox dicFile & " not found in Dictionaries collection"
    Else
        MsgBox "Error " & Err.Number & vbCr & Err.Description
    End If
End Sub

(edit) STOP HERE

Save the Normal template by using the Save command in the macro editor (not in the main Word window).

The second part:
Copy/paste the following code into the ContextMacros module (or any other module; this isn't critical).

Sub BuildControls()
  Dim cb As CommandBar
  Dim octrl As CommandBarControl
  Dim oBtn As CommandBarButton
  Dim bPatient As Boolean, bProduct As Boolean
 
  'On Error GoTo errhdl
 
  'Make changes to the Normal template
  CustomizationContext = NormalTemplate
 
  'Add new entries on the Text context menu
  Set cb = CommandBars("Spelling")
 
  'Avoid duplication
  For Each octrl In cb.Controls
    If (octrl.Caption = "Add to MyPatientNames") Then
      MsgBox "PatientNames entry exists already"
      bPatient = True
    End If
    If (octrl.Caption = "Add to MyMTProducts") Then
      MsgBox "Products entry exists already"
      bProduct = True
    End If
  Next octrl
 
  If bPatient Then GoTo skipPatient
  'Add entry
  Set oBtn = cb.Controls.Add(Type:=msoControlButton, Before:=1)
  With oBtn
    .Caption = "Add to MyPatientNames"
    .Style = msoButtonCaption
    'Identify the module and procedure to run
    .OnAction = "ContextMacros.AddToMyPatientNames"
  End With
  Set oBtn = Nothing
  MsgBox "Added PatientNames entry"

skipPatient:
  If bProduct Then GoTo done
  'Add entry
  Set oBtn = cb.Controls.Add(msoControlButton, Before:=2)
  With oBtn
    .Caption = "Add to MyMTProducts"
    .Style = msoButtonCaption
    'Identify the module and procedure to run
    .OnAction = "ContextMacros.AddToMyMTProducts"
  End With
  Set oBtn = Nothing
  MsgBox "Added Products entry"
 
done:
  Set cb = Nothing
  Exit Sub
 
errhdl:
  MsgBox Err.Description
End Sub

Sub RemoveControls()
Dim oCtr As CommandBarControl
  CustomizationContext = NormalTemplate
For Each oCtr In Application.CommandBars("Spelling").Controls
    If (oCtr.Caption = "Add to MyPatientNames") Or _
    (oCtr.Caption = "Add to MyMTProducts") Then
      oCtr.Delete
    End If
  Next oCtr
End Sub

Now, this needs to be done only once: Put the cursor on the Sub BuildControls() line and press F5 to run the macro. That will create the two entries at the top of the right-click menu that pops up when you right-click a word that's marked as a spelling error. (It won't appear on any other right-click menu.)

The RemoveControls() macro is there just in case you ever want to remove the two entries from the Spelling menu.

The third part:
If the MyPatientNames.dic and MyMTProducts.dic custom dictionaries don't appear on the Options > Proofing > Custom Dictionaries dialog or aren't checked to make them available, then the macros will pop up an error message when you try to use them. Go to the dialog and make sure the custom dictionaries are available.
_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer
It isn't a matter of the macro finding or not finding the UProof folder; the error message occurs when one of the dictionaries MyPatientNames.dic and MyMTProducts.dic is not in the CustomDictionaries collection.

I don't believe there's any difference between Word 2007 and Word 2010 in this area. What I think happened is that you may have missed this sentence in my initial post:

"The third part is to use the Options > Proofing > Custom Dictionaries dialog to create the two dictionaries and add them to the dictionaries collection, if they aren't already there."

Your my3() macro does the same thing, adding the dictionaries to the CustomDictionaries collection.


_____________________________
https://jay-freedman.info

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 29, 2024 Views 783 Applies to: