Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Word 2003 macros run slowly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martyn Walmsley - 12 Jul 2005 12:24 GMT
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
Jay Freedman - 12 Jul 2005 13:10 GMT
>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.
[quoted text clipped - 5 lines]
>
>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.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Martyn Walmsley - 12 Jul 2005 15:17 GMT
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.

> >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.
[quoted text clipped - 16 lines]
> Jay Freedman
> Microsoft Word MVP         FAQ: http://word.mvps.org
Jay Freedman - 12 Jul 2005 16:36 GMT
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.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Jay
>
[quoted text clipped - 43 lines]
>> Jay Freedman
>> Microsoft Word MVP         FAQ: http://word.mvps.org
Howard Kaikow - 12 Jul 2005 20:03 GMT
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.
Signature

http://www.standards.com/; See Howard Kaikow's web site.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.