Word 2003 macros run slowly

M

Martyn Walmsley

Running a 13 line Word 2003 macro containing 1 for...next loop with 6 lines
in it, even with application.screenupdating=false, takes 44 seconds to run.
Given that the PC I'm running it on has 4 Xeon 2.8 Ghz processors with Hyper
threading turned on and 2Gb Ram; I wouldn't expect to be able to start the
stopwatch, let alone go for a coffee in the time it takes to run.
Are there any options in Word 2003 that could impact the running of macros
to this extent?

Thanks
 
J

Jay Freedman

On Tue, 12 Jul 2005 04:24:02 -0700, Martyn Walmsley <Martyn
Running a 13 line Word 2003 macro containing 1 for...next loop with 6 lines
in it, even with application.screenupdating=false, takes 44 seconds to run.
Given that the PC I'm running it on has 4 Xeon 2.8 Ghz processors with Hyper
threading turned on and 2Gb Ram; I wouldn't expect to be able to start the
stopwatch, let alone go for a coffee in the time it takes to run.
Are there any options in Word 2003 that could impact the running of macros
to this extent?

Thanks

The number of loops and lines and the power of the hardware have
absolutely nothing to do with how long a macro takes to execute -- I
can write a one-line macro that never finishes. The question is, what
is the macro doing, and is there a better way to do it? Post your code
so we can help.
 
M

Martyn Walmsley

Jay

Here's the code

Sub FieldPropertiesBookmark()
'
'This will put the Open and Close requirements round the 6 element field
definitions
Application.ScreenUpdating = False
Call TDWordAddin.mdlRequirments.OpenRequirement 'Inserts a bookmark
Selection.MoveDown Unit:=wdLine, Count:=1
For Field = 1 To 6
Call TDWordAddin.mdlRequirments.OpenRequirement 'Inserts a bookmark
Selection.InsertParagraphAfter
Selection.MoveDown Unit:=wdLine, Count:=1
Call TDWordAddin.mdlRequirments.CloseRequirement 'Inserts a
bookmark
Selection.MoveDown Unit:=wdLine, Count:=1
Next
Call TDWordAddin.mdlRequirments.CloseRequirement 'Inserts a bookmark
Selection.MoveDown Unit:=wdLine, Count:=1
Application.ScreenUpdating = True
End Sub

There are a large number of bookmarks in the document which are used as
placeholders for importing text into Mercury's Quality Center.
 
J

Jay Freedman

Hi Martyn,

I don't know what the addin is doing -- in addition to the simple comment
"Inserts a bookmark", it must be finding the locations and keeping track of
the bookmark names, and possibly doing other work -- but I suspect that at
least part of the slowness comes from the overhead of calling the addin
repeatedly.

Another typical cause of slowness is using the Selection object instead of a
Range object, which incurs the cost of recomputing and possibly repaginating
the document, even when ScreenUpdating is turned off.

If this is a serious enough problem, I'd suggest reviewing what the addin is
doing, and rewriting the macro (and possibly the addin, if that's within
your control) to do all the work with Range objects.
 
H

Howard Kaikow

Try something like:

with Application
.ScreenUpdating = False
with TDWordAddin.mdlRequirments
Call .OpenRequirement 'Inserts a bookmark
Selection.MoveDown Unit:=wdLine, Count:=1
For Field = 1 To 6
Call .OpenRequirement 'Inserts a bookmark
Selection.InsertParagraphAfter
Selection.MoveDown Unit:=wdLine, Count:=1
Call .CloseRequirement 'Inserts a bookmark
Selection.MoveDown Unit:=wdLine, Count:=1
Next
Call .CloseRequirement 'Inserts a bookmark
end with
Selection.MoveDown Unit:=wdLine, Count:=1
.ScreenUpdating = True
end with

And change OpenRequirement, CloseRequirement and the above code to use the
Range, instead of the Selection, object.
 

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