spellchecking again

S

Sebastian Kress

Hey there,

with the help of some guys here, I managed to create an automated list
of spelling errors in word documents.

I used the following code:

--------

Sub ListSpellingErrors()

Dim lngSpellErrCnt As Long, n As Long, FFile As Integer
lngSpellErrCnt = ActiveDocument.SpellingErrors.Count

FFile = FreeFile 'DateiHandle
Open "C:\SpellErr.txt" For Output As #FFile
For n = 1 To lngSpellErrCnt
Print #FFile, ActiveDocument.SpellingErrors(n).Text
Application.StatusBar = n & " / " & lngSpellErrCnt & " Fehler
verarbeitet..."
Next
Close #FFile

End Sub

--------

It works quite ok, actually, but it's unbelievably slow. Can anyone tell
me why?

Thanks,
Sebastian
 
W

Word Heretic

G'day Sebastian Kress <[email protected]>,

The big killer here is your status display because of the string
concats. Add to that I/O is the slowest aspect of any program and you
have your answer.

To speed it up:

1) only show the status bar every 10 repetitions

2) output to a temp document and then save the document as text. No
I/O until the end

Dim Report as Document
Dim Source as Document
Dim InsertPoint as Range
....

Set Source=ActiveDocument
Set Report=Documents.Add
Set InsertPoint = Report.Content
InsertPoint.Collapse

then instead of
Print #FFile, ActiveDocument.SpellingErrors(n).Text

use

InsertPoint.InsertAfter Source.SpellingErrors(n).Text
Inserpoint.InsertParagraphAfter

....

Report.SaveAs "<your filename>",wdFormatText

I cover standard VBA optimisations in my Word VBA Beginner's
Spellbook, available from my site.

Steve Hudson - Word Heretic Sydney Australia
Word eTutor

steve from wordheretic.com (Email replies require payment)


Sebastian Kress reckoned:
 

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