Performance problems relating to Word dictionaries

R

Rod

About 2-3 years ago we developed (in Word97 VBA) an
application to parse and classify documents. It worked
well handling a 5 page document in approximately 2-3
minutes.

Recently we migrated all our code over to Office 2000 and
we are suddenly having large performance problems with
this particular piece of code. We have profiled the code
and it appears that the majority of time is spent on just
one function call namely...

KnownWordDetected = Application.CheckSpelling
(Word:=TextToInspect,
CustomDictionary:=SkillKeywordsToIgnoreDictionary,
IgnoreUppercase:=True)

Just prior to this call we make the following statement

WordBasic.ToolsLanguage Language:="English (UK)"

We have configured " Microsoft office language settings"
to use English (UK).

Has anyone got any ideas what the performance problem
might be caused by.

many thanks in advance
 
J

Jonathan West

Hi Rod,

I'm not sure what the problem is here, as I haven't used the CheckSpelling
method in macros, but here are some things to try & check.

1. Are you doing the ToolsLanguage command every time you look for a word?
If so, try moving that command outside the loop so that it doesn't execute
every time. You probably only need to set the language once, at the start of
the macro.

2. I assume the SkillKeywordsToIgnoreDictionary variable points to a file
which contains your custon dictionary. Has that dictionary moved? Is the
variable referring just to the name or to the full path?

3. If the custom dictionary is already loaded, have you tried making the
variable an object variable which points to the appropriate Dictionary
object? this might save the time involved in re-loading the dictionary each
time.
 
P

Peter Schaeffner

-----Original Message-----

Hi Rod, Jonathan,

Just thought I'd throw in my 2c, because I use the
CheckSpelling method a lot.
1. Are you doing the ToolsLanguage command every time you
look for a word?
If so, try moving that command outside the loop so that
it doesn't execute every time. You probably only need to
set the language once, at the start ofthe macro.

Exactly. And Rod, if you don't want to do this with your
original document, perhaps create a copy of it. Since you
stated your documents are fairly small, you can do it the
easy way, something like this:
Documents(docTemp).Content = ActiveDocument.Content
Documents(docTemp).Content.LanguageID = wdEnglishUK
2. I assume the SkillKeywordsToIgnoreDictionary variable
points to a file which contains your custon dictionary.

Yes, you can "include" :) an additional custom dictionary.
And this is perhaps where part of the performance goes, it
being internally added and cleared every time the loop
loops. :)
Rod, perhapy try to add that special dictionary at the
beginning of the evaluation of the document, and then
clear it when you are finished. This way you can omit the
parameter 'CustomDictionary' altogether.
3. If the custom dictionary is already loaded, have you
tried making the variable an object variable which
points to the appropriate Dictionary object? this might
save the time involved in re-loading the dictionary each
time.

That probably wouldn't speed the process up, I think. If
the custom dictionary is already loaded, Word should be
able to do that on it's own. (Oh my god, I HOPE Word is
able to do that! <g>)
If the custom dictionary is loaded, Word loads it into
memory at startup (or when you add it to the list of
loaded custom dictionaries).


The main problem Rod has is in fact Office 2000: the
CheckSpelling method of Office 2000 is way (!) slower than
in Office 97. And there is no way around it.


But, in Rod's case I have a hunch. Pondering the names he
gave the variables, he perhaps just wants to know if a
certain word is in that dictionary. If so, there is a much
faster way: InStr.
So, Rod, if I'm right, you could do this: read the
dictionary as it is in a variable and put a vbCrLf in
front of it. Because then you can search your word like
this:
If InStr(1, varDic, vbCrLf & strYourWord & vbCrLf) > 0 Then
....

As said, just a hunch.

See ya
Peter

----
 

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