How do I delete all words that are mispelled in a document?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a document with 50k words and I would like to delete all the words
that are underlined red or not recognized by the dictionary automatically.
Going one by one is taking much too long!! Anyone know how?
 
You could try running a macro something like this:

Sub Test()
Dim myErrors As ProofreadingErrors
Dim myErr As Range
Set myErrors = ActiveDocument.Range.SpellingErrors
If myErrors.Count = 0 Then
MsgBox "No spelling errors found."
Else
For Each myErr In myErrors
myErr.Delete
Next
End If
End Sub
 
I have a document with 50k words and I would like to delete all the words
that are underlined red or not recognized by the dictionary automatically.
Going one by one is taking much too long!! Anyone know how?

Use this macro (see http://www.gmayor.com/installing_macro.htm):

Sub DeleteAllMisspelledWords()
Dim myErrors As ProofreadingErrors
Dim myErr As Range

Set myErrors = ActiveDocument.Range.SpellingErrors
If myErrors.Count = 0 Then
MsgBox "No spelling errors found."
Else
For Each myErr In myErrors
myErr.Delete
Next
End If
End Sub
 
Hey, I had to do *something* creative while I was copying code out of
the Help topic. ;-)
 
Just a thought. Isn't your text going to look a bit funny with all those
words missing? Wouldn't you want to replace them with something? I am
trying to imagine, say, the Gettysburg Address after these macros rip out
any fancy words Abe used that might have triggered the wavy red lines.
Would it be sort of like "And seven years ago our brought on this continent
a new nation in liberty and to the that all men are created." Sounds odd.
Heck of a lot simpler, though.
 
thannk you guys! I will try the Macros. This is actually a word list and I
have eliminate words that are not recognized by the Word Dictionary. No
sentences or anything like that just thousands and thousands of words. I
started to do a few pages then quickly realized there had to be a better way.
 
It worked!! Just as a note...it kept locking up when I tried it on the full
doc (250 pages...856k), but I divided the doc into 4 smaller parts and then
it worked just fine.

Would anyone know how to delete words that don't have Synonyms? In other
words a word that when you right click on shows nothing under synonyms.
 
Ooh, a puzzle poser! :-)

Public Sub NoSynonyms()
Dim oWord As Range
Application.ScreenUpdating = False
For Each oWord In ActiveDocument.Words
With oWord
If .SynonymInfo.MeaningCount = 0 Then
.Delete
End If
End With
Next oWord
Application.ScreenUpdating = True
End Sub

Careful, though -- this one is going to run only slightly less than
forever. You'll probably have to split your document into even more
pieces.
 
I appreciate it Jay, you sure know WORD well!.....and thanks for the warning
 
Hi Greg
I know it's a long time since your post below. (I'm using MVB 6.5 with Word
2007. Maybe therein lies the problem).
I'm trying to apply your macro to 75 files containing around 3,000 words
each (i.e. sub-files of a Scrabble dictionary, which, thanks to Doug Robbins,
I was successfully able to split) The macro works most of the time (I'm up to
file 31 after several retries). I get repeatedly the VB error ' Run-time
error '4608' Application-defined or Object-defined error. On clicking 'debug'
it points to the 'Next' statement in your macro as listed below. I'm using
exactly that coding. Would appreciate any 'get-arounds' just to get me
through the 75 files. (And of course, thanks for the macro anyway)

Brian
 
I don't know what MVB is.

You might try:
Sub Test()
Dim myErrors As ProofreadingErrors
Dim myErr As Range
Dim i As Long
Set myErrors = ActiveDocument.Range.SpellingErrors
If myErrors.Count = 0 Then
MsgBox "No spelling errors found."
Else
For i = myErrors.Count To 1 Step -1
MsgBox myErrors(i).Text
myErrors(i).Delete
Next i
End If
End Sub
 
Thanks Greg for the rapid response. Sorry about the MVB abbreviation of my
own making. (Microsoft Visual Basic).
I don't come back to you lightly. I've been trying for days to batch your
coding for the now 137 X 20K files of around 1,500 words each. (50% of which
have spelling errors or not English).
It works, as is, fine. i.e. open a file and run the macro on the active file
(I've REM'd the two MSG's to stop having to answer the screen messages). That
is, I open a target file manually in Word 2007 and launch the macro. The
macro continues with the then active file which then gets the red underlines
automatically which the macro deletes. However, when I insert a
DOCUMENTS.OPEN statement (to facilitate batching the 137 files for
processing) it simply fails to do the red underlining and deleting. That is,
the macro completes very quickly having done nothing. The modified code is:-


Sub Test()
Dim myErrors As ProofreadingErrors
Dim myErr As Range
Dim i As Long


Documents.Open FileName:="""c:\users\bhep\documents\scrabble75files\English
(UK)001.srb"""


Set myErrors = ActiveDocument.Range.SpellingErrors
If myErrors.Count = 0 Then
REM MsgBox "No spelling errors found."
Else
For i = myErrors.Count To 1 Step -1
REM MsgBox myErrors(i).Text
myErrors(i).Delete
Next i
End If
ActiveDocument.Save
ActiveDocument.Close

End Sub

I can't get my head around looping at the moment so I'll simply include the
above coding 137 times with filenames ....001.srb to ....137.srb if I can get
it working.

Very much appreciate your help so far.

How can I force the spellchecker to activate. i.e. do its thing of red
underlining to allow the deletes to take place?

Best regards

Brian
 
Hi Greg - Oops, forget my last post. Problem lay with language environment.
As I live in Switzerland I'd activated German and French as well as US and UK
English. A 'wrong' word seems to have sent the spellchecker off looking for a
German reference dictionary, which I don't have. Configuring out the German
and French languages was the solution. Your macro (batched) is into its 15th
hour - 240 hours to go (well I only have a 1.8Ghz X 1Gb on my Vista pc). At
the end I'll have a Microsoft clean Scrabble dictionary. All I'll then need
to do is anglicise it!

Thanks for your help.

Kind regards

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top