Spellcheck and Ignore All

G

George Lee

I am trying to uniquely list all the misspelled words in a document. After
finding a misspelled word, how can program VBA to ignore all just like you
would do from the spellcheck dialog box?
The code starts something like this:
For Each mySpellingError In ActiveDocument.Range.SpellingErrors
UserForm1.ListBox1.AddItem mySpellingError.Text
'Now ignore all the word so I don't encounter it again
Next
 
T

Tony Jollans

Hi George,

I don't know how to do it without the Selection but try this ...

mySpellingError.Select
CommandBars("Spelling").Controls("Ignore All").Execute
 
M

Martin

How about:

Sub mySpelling()
Dim mySpellingError
Dim n As Long
Dim myFlag As Boolean
For Each mySpellingError In ActiveDocument.Range.SpellingErrors
myFlag = False
For n = 0 To UserForm1.ListBox1.ListCount - 1
If UserForm1.ListBox1.List(n) = mySpellingError.Text Then myFlag
= True
Next
If myFlag = False Then
UserForm1.ListBox1.AddItem mySpellingError.Text
End If
Next
UserForm1.Show
End Sub
 
G

George Lee

Greg has an excellent site and any one working with spelling should check it
out. I based a lot of code from this.
 
G

George Lee

Can you provide more details about this? I like the idea but I don't have a
command bar named "Spelling."
 
T

Tony Jollans

It is built-in popup menu. I thought it might be version dependent but have
just checked in Word 2000 and it works for me there. It will only have an
"Ignore All" control if the selection is on a spelling error but the command
bar should always exist - assuming you have an English version of Word.
 
C

Chaim

First this is not all my own work. The main peice came from http://www.
experts-exchange.
com/Software/Office_Productivity/Office_Suites/MS_Office/Q_20293035.html?
qid=20293035
it is a macro that lists all words.
I put it together with some code from http://www.officekb.com/Uwe/Forum.
aspx/word-vba/10923/Misspelled-words
which showed me how to move from misspelled word to misspelled word. (use
answer #2)
So I do not use the ignorall. I creat an array of misspelled words. Then I
go from word to word ching if I already have it and adding any I don't yet
have.Finaly I put that out as a new document.

So at long last here is the code

Sub misspelled()


Dim SingleWord As String 'Raw word pulled from doc
Const maxwords = 9000 'Maximum unique words allowed
Dim Words(maxwords) As String 'Array to hold unique words

Dim WordNum As Integer 'Number of unique words
Dim MSWs As ProofreadingErrors 'Spelling errors

Dim ttlwds As Long 'Total words in the document
Dim Found As Boolean 'Temporary flag
Dim j, k, l, Temp As Integer 'Temporary variables
Dim tword As String '
Dim Ans As String

Dim MWord As Range 'active word

Dim tmpName As String

'seting variables and conditions
System.Cursor = wdCursorWait
WordNum = 0
Set MSWs = ActiveDocument.SpellingErrors
ttlwds = ActiveDocument.SpellingErrors.Count

' Control the repeat
For Each MWord In MSWs

SingleWord = Trim(LCase(MWord))
If SingleWord < "a" Or SingleWord > "z" Then SingleWord = ""
'Out of range?
If Len(SingleWord) > 0 Then
Found = False
For j = 1 To WordNum
If Words(j) = SingleWord Then
Found = True
Exit For
End If
Next j
If Not Found Then
WordNum = WordNum + 1
Words(WordNum) = SingleWord
End If
If WordNum > maxwords - 1 Then
j = MsgBox("The maximum array size has been exceeded.
Increase maxwords.", vbOKOnly)
Exit For
End If
End If
ttlwds = ttlwds - 1
StatusBar = "Remaining: " & ttlwds & " Unique: " & WordNum
Next MWord


' Now write out the results
tmpName = ActiveDocument.AttachedTemplate.FullName
Documents.Add Template:=tmpName, NewTemplate:=False
Selection.ParagraphFormat.TabStops.ClearAll
With Selection
For j = 1 To WordNum
.TypeText Text:=vbTab & Words(j) & vbCrLf
Next j
End With
System.Cursor = wdCursorNormal
j = MsgBox("There were " & Trim(Str(WordNum)) & " different words ",
vbOKOnly, "Finished")
Selection.HomeKey wdStory

Food luck
 

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

Top