rob nobel said:
Malcolm,
That sortoff works great. It works fine if there's not too many pages this
procedure has to go through. (Did about 150 pages or so OK in about 1/4
hour).
Trouble is, there are about 2600 pages in this document and unless I copy
small sections to other documents and run the procedure separately on each
document, the procedure just whirrs away for hours and ctrl+alt+del tells me
that although the procedure's running, it's not responding.
For a document that big, the bottleneck is the For Each statement, which
gets very slow on large collections of paragraphs. Use this instead that
will be a lot faster
Sub DelectSpellingErrors()
Dim oPara As Paragraph
Dim oSpellingSuggestions As SpellingSuggestions
Set oPara = ActiveDocument.Paragraphs(1)
Do Until oPara.Range.End = ActiveDocument.Range.End
Set oSpellingSuggestions = oPara.Range.GetSpellingSuggestions
If oSpellingSuggestions.SpellingErrorType = wdSpellingNotInDictionary
Then
oPara.Range.Delete
Else
Set oPara = oPara.Next
End If
Application.StatusBar = CStr(Int(100 * _
oPara.Range.End / ActiveDocument.Range.End)) & "% complete"
Loop
End Sub
As a bonus, I've included a line of code that will give you a percent
complete indication the the status bar.
I'm grateful already for what you've provided, but is there a problem with
it or is the file just to large for Word to handle the procedure in one big
file?
Also, can you tell me what the "o" means in front of some of the code? Is
that something specific you do in codes you provide or does it actually do
something ?(I'm still a beginner with VBA.)
The o on the start of some variable names is a naming convention commonly
adopted to indicate that the variable is an Object of some sort (integers
often have an i prefix, and strings an str prefix). This has two benefits,
first of all, it is a reminder to you what the variable does, and second, it
eliminates any chance of accidentally giving a variable the same name as a
built-in object or keyword.