Word

Assisted spell check for visually impaired

Ease of Use

Intermediate

Version tested with

 

Submitted by:

mdmackillop

Description:

The maco halts input if a spelling error occurs. This is triggered by the spacebar during normal use. The typist has the option to reype over the selected misspelling, to ignore, or to add to the custom dictionary. Beeps are sounded to indicate appropriate actions. 

Discussion:

For use by those with a visual impairment, or, like me, cannot take their eyes off the keyboard. 

Code:

instructions for use

			

Option Explicit Sub SetSpacebar() CustomizationContext = NormalTemplate 'Create key binding KeyBindings.Add KeyCode:=BuildKeyCode(wdKeySpacebar), _ KeyCategory:=wdKeyCategoryMacro, _ Command:="CheckLastWord" DoBeep 0.1, 2 MsgBox "Spacebar macro is on" End Sub Sub ClearSpacebar() Dim aKey CustomizationContext = NormalTemplate 'Look for key and delete if found, then exit sub For Each aKey In KeyBindings If aKey.KeyString = "Space" Then FindKey(BuildKeyCode(wdKeySpacebar)).Clear DoBeep 0.1, 1 MsgBox "Spacebar Off" Exit Sub End If Next aKey End Sub Sub CheckLastWord() Dim ec As Object, i!, tm As Double, Decide As String ' Insert a space Selection.TypeText Text:=" " ' Select word just typed including space with cursor to left of word Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend ' Set ec to count errors in selected text Set ec = Selection.Range.SpellingErrors ' move cursor to the right of word just typed Selection.MoveRight Unit:=wdCharacter, Count:=1 ' Triple beep if there is an error If ec.Count > 0 Then 'Halt input until correction made MsgBox "Pauses" For i = 1 To 3 'Set no. of beeps tm = Timer Do DoEvents Loop Until Timer - tm > 0.15 'Set beep speed Beep Next i ' select the word just typed ready for retyping Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend ' Now ask user if word is OK and to be added to dictionary Decide = MsgBox("Add new word", 259, "Check Spelling") 'Add word to dictionary If Decide = vbYes Then AddCustomWord 'Allows retyping of word If Decide = vbNo Then DoEvents 'Ignore and move on to next word If Decide = vbCancel Then Selection.MoveRight Unit:=wdCharacter, Count:=1 End If End Sub Sub AddCustomWord() Dim NewWord As String, CustomWord As String 'Trim end space from selection NewWord = Left(Selection, Len(Selection) - 1) 'Enter as default on input box This can be deleted if InputBox not desired CustomWord = InputBox("Custom word to be added", , NewWord) If CustomWord = "" Then Exit Sub 'Set correct path to Custom.dic ******************************************* Documents.Open FileName:= _ "C:\Documents and Settings\USERNAME\Application Data\Microsoft\Proof\CUSTOM.DIC" Selection.TypeText NewWord & Chr(13) ActiveWindow.Close wdSaveChanges = True 'Move selection to continue typing Selection.MoveRight Unit:=wdCharacter, Count:=1 'Set beep response; Rate, Beeps DoBeep 0.1, 2 End Sub Sub DoBeep(Rate, Bps) Dim i!, tm As Double For i = 1 To Bps 'Set no. of beeps tm = Timer Do DoEvents Loop Until Timer - tm > Rate 'Set beep speed Beep Next i End Sub

How to use:

  1. Copy code.
  2. From Word, press Alt + F11.
  3. Select file on left, press Insert -> Module.
  4. Paste code on right.
  5. Set the correct path to Custom.dic where indicated below the asterisks.
  6. In ThisDocument module, Add DocumentOpen and DocumentClose macros to call SetSpacebar and ClearSpacebar respectively (as shown in example file).
  7. Save and close the document.
  8. On reopening, the macro should start automatically.
  9. More detailed instructions for use are given in the attached file
 

Test the code:

  1. Open the document and make a deliberate misspelling.
  2. Press the spacebar.
 

Sample File:

SpellCheckAssist.zip 13.12KB 

Approved by mdmackillop


This entry has been viewed 84 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express