VBA much slower in Word 2007 than Word 2003

R

Ron Smith

I create family history books (genealogy) for our extended family. The books
are very large ranging from 100 to 1500 pages (yes, I use sub-documents where
I can). The books contain huge numbers of footnotes and footnote
cross-references as all facts are documented by sources where possible.
There are also a great many pictures included via links to the files
(definitely not embedded in the document).

To aid in managing the information, format, etc., I've generated a lot of
very large macros that are in a Genealogy.dot (.dotm) template that I attach
to the book files. For example, when I insert more text from other sources,
I'm typically inserting duplicate references (footnotes). One macro scans
all footnotes for duplicate text, finds all cross references to the one to be
deleted and changes them to cross-references to the one being changed and
then changes the one to be deleted it to a cross-reference to the lower
numbered one. Another one just scans all cross-references, ensures a comma
and single space between them, sorts them into numerical order, and makes
sure that the "Footnote references" style is applied to the whole string.

Now the question. Those macros run in just a few minutes (2-5) on my
largest document of 1500 pages, 2500 footnotes, and 25,000 footnote
cross-references in Word 2003. It runs in multiple hours on Word 2007 (I
typically run it overnight). My computer is a 2GHz system with 2GB of memory
so not very fast, but with plenty of memory. I'm running Windows XP Pro.
I'll upgrade to Vista when I buy a new machine in a year or so.

I learned through forums like this and trial-and-error in Word 2003 what the
best programming practices were. For example, always use For Each ... Next
and never use indices to loop through things like footnotes, fields, etc.
Apparently, indices always started from the beginning and just counted
through the fields. The times were like what I'm seeing now in Word 2007.
So, are there new best practices for Word 2007 macros that will help?

Thanks very much,
 
Y

yves

Hi Ron,

with 2K7, all parts of your source code that tweak Word settings or
document view (display) options will run considerably slower than in
previous versions of Ms-Word. I have not yet discovered the exact
mechanics behind this - I suppose that tweaking triggers a lot of
precautions which, and even in the case you have the right to tweak
settings, this will slow down the process.

Look for all actions that tweak Options.something and
ActiveWindow.View.something settings. See if they're absolutely
necessary. If you have groups of settings, make sure they're called
with a With... End With structure. Make sure such calls are not
redundant, or not unnecessarily repeated within a loop.

Hope this helps,
Yves Champollion
www.champollion.net
 
R

Ron Smith

Thank you,

I'll check that. I don't think that's the primary problem though. In the
part of the macro where the most time goes, I'm scanning through the footnote
references with a For Each refFld In ActiveDocument.Fields
loop. That loop seems to be an order of magnitude slower in 2007.

Ah well, I'll play with some other approaches and see what happens.
 

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