Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Word VBA: how to add an item to a spelling dictionary

    Hi all,

    I can't seem to find a way in VBA to add an item to a spelling dictionary.

    I wanted to make a keyboard shortcut to add to the dictionary a word flagged as a spelling error (flagged by the wavy red underline). I could not find a preset user command for this (to which to apply a shortcut key), so I decided to program my own in VBA.

    However, I could not persuade Word to reveal its dictionary API secrets by recording a macro while adding a word to the dictionary when using the Spell Checker.

    Can somebody tell me how to do this in VBA?

    TIA

    -avraham

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    avraham,

    Why not just right click on the red line and select Add to Dictionary no VBA needed.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    05
    Hi RetiredGeek,

    Thanks for the response.

    I simply want to add new terms to the dictionary without taking my hands off the keyboard.

    I am writing about a new subject and so I am entering lots of new terms that are causing lots of spelling errors, and so I wanted to add them as I go along.

    Blessings

    avraham

  4. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Avraham,

    Here's how to do it with the keyboard. This assumes you catch it just after you complete the new word, otherwise it's a lot of backing up.

    1. Use the back arrow key to get back in the word with the red line.
    2. Press the Menu key { I had to use my wife's laptop to test this as mine doesn't have the key1}
    3. Press "A" to add the word.

    Hope you have a menu key and this helps.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    This is pretty terrible, but the shortcut menu seems to be constructed dynamically, so it's difficult to determine how to run the "Add to Dictionary" command directly.

    Code:
    Sub SpellingAddToCustomDict()
    Dim perr As Word.ProofreadingErrors, rngSave As Word.Range, rngTemp As Word.Range
    ' Store selection position to restore after spell check dialog moves on
    Set rngSave = Selection.Range
    ' Create a range backwards from the selection start
    Set rngTemp = ActiveDocument.Range(Selection.Start, Selection.Start)
    rngTemp.MoveStart wdStory, -1
    Set perr = rngTemp.SpellingErrors
    If perr.Count > 0 Then
        'If MsgBox("Add " & perr.Item(perr.Count).Text & " to the Custom Dictionary?", vbQuestion + vbYesNo) = vbYes Then
            SendKeys "a{ESC}"   ' Ugly! Sends A to spell check dialog then cancels it when it redisplays
            perr.Item(perr.Count).CheckSpelling
            rngSave.Select
        'End If
    End If
    Set perr = Nothing
    Set rngTemp = Nothing
    End Sub

Posting Permissions

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