Results 1 to 6 of 6
  1. #1
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete Words not in Dictionary (Word 97)

    Does anyone know of a command or macro that will delete words from a highlighted list or paragraph that are NOT in the MS Word dictionary. I want to remove the words from the file itself.

    Thanks,

    Chris (Hunt)

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Delete Words not in Dictionary (Word 97)

    This seems to do the trick
    <code>
    Sub DelWordsNotInDic()
    Dim i As Integer
    For i = Selection.Range.SpellingErrors.Count To 1 Step -1
    Selection.Range.SpellingErrors(i).Words(1).Text = ""
    Next i
    End Sub
    </code>
    StuartR

  3. #3
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Words not in Dictionary (Word 97)

    Thanks Stuart, that's great. I managed to create the following macro by amending one I found via a google search:

    Sub deldic()
    Dim oWord As Range
    Dim StoryRange As Range
    For Each StoryRange In ActiveDocument.StoryRanges
    Application.CheckSpelling Word:=StoryRange
    For Each oWord In StoryRange.Words
    If Not Application.CheckSpelling(Word:=oWord.Text) Then
    oWord.Delete
    End If
    Next oWord
    Next StoryRange
    End Sub

    But I feel yours is more elegant. Currently, each word is on a separate line and when the words are removed gaps are created in the list. Can you recommend a good way to remove unneeded paragraph marks to close up the list. Currently I'm doing multiple replaces (replacing ^p^p with ^p) but I'm sure there must be a better way.

    Thank again,

    Chris

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Words not in Dictionary (Word 97)

    Stuart's version, amended:

    Sub DelWordsNotInDic()
    Dim i As Integer
    Dim rng As Range
    For i = Selection.Range.SpellingErrors.Count To 1 Step -1
    Set rng = Selection.Range.SpellingErrors(i).Words(1)
    rng.Expand Unit:=wdParagraph
    rng.Delete
    Next i
    End Sub

  5. #5
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Words not in Dictionary (Word 97)

    Thanks Hans, that works a treat.

    Best wishes,

    Chris

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Delete Words not in Dictionary (Word 97)

    A sightly neater option would be
    <code>
    Sub DelWordsNotInDic()
    Dim i As Integer
    For i = Selection.Range.SpellingErrors.Count To 1 Step -1
    Selection.Range.SpellingErrors(i).Paragraphs(1).Ra nge.Delete
    Next i
    End Sub
    </code>
    But I haven't tested what this code would do if there was more than one spelling error in a paragraph!

    StuartR

Posting Permissions

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