M
Mcollette
I have a fairly complex macro that combs a document for acronyms and
their definitions, then writes them in a new document.
The macro uses the find object to look for words consisting of two or
more capital letters. When it finds a word, it performs some checks to
see whether the word should be ignored. It looks for bold formatting,
whether the word is in a table, and whether the word appears in a string
of commonly capitalized words that we use (uses the InStr comparison to
accomplish the latter.) Any of these conditions causes it to ignore the
word and move on.
If it doesn't skip the word, it then checks to see whether the word is
inside parentheses. If it is, it uses the find object again to search
for capitalized words in front of the acronym, and records those words
as the definition. The acronyms and definitions are stored in two long
strings, and at the end of the macro, it pulls the information from
those strings to write in the new documents.
For a 94-page document, it's taking about 1 minute and 30 seconds to
run. Some of the documents we work with are going to be much larger than
this, and I can only imagine that the process will slow even more the
further it gets into a document.
I've dropped some Document.UndoClear lines in the loops, and that might
have helped a little, but I think the biggest problem is repaginating.
Even with code that switches the document to normal view and turns
background repagination off, Word is still repaginating while the macro
runs. I'm not sure what code is triggering this.
I've tried running it with the application invisible, but that doesn't
seem to help much. Also, I don't really want to keep the application
invisible because I'm giving the user the option of being prompted when
the macro encounters an acronym. The acronym is highlighted so the user
can see it in context, decide whether it should be in the table, and
then press Yes or No.
Any advice on improving speed?
their definitions, then writes them in a new document.
The macro uses the find object to look for words consisting of two or
more capital letters. When it finds a word, it performs some checks to
see whether the word should be ignored. It looks for bold formatting,
whether the word is in a table, and whether the word appears in a string
of commonly capitalized words that we use (uses the InStr comparison to
accomplish the latter.) Any of these conditions causes it to ignore the
word and move on.
If it doesn't skip the word, it then checks to see whether the word is
inside parentheses. If it is, it uses the find object again to search
for capitalized words in front of the acronym, and records those words
as the definition. The acronyms and definitions are stored in two long
strings, and at the end of the macro, it pulls the information from
those strings to write in the new documents.
For a 94-page document, it's taking about 1 minute and 30 seconds to
run. Some of the documents we work with are going to be much larger than
this, and I can only imagine that the process will slow even more the
further it gets into a document.
I've dropped some Document.UndoClear lines in the loops, and that might
have helped a little, but I think the biggest problem is repaginating.
Even with code that switches the document to normal view and turns
background repagination off, Word is still repaginating while the macro
runs. I'm not sure what code is triggering this.
I've tried running it with the application invisible, but that doesn't
seem to help much. Also, I don't really want to keep the application
invisible because I'm giving the user the option of being prompted when
the macro encounters an acronym. The acronym is highlighted so the user
can see it in context, decide whether it should be in the table, and
then press Yes or No.
Any advice on improving speed?