View Single Post
 
Old 05-09-2018, 05:48 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

So a couple of things I would try to speed it up.

1. Use objects you already have in memory to reduce the number of memory steps required on a line. Once you have oShp in memory, there is no need to step back up multiple levels to use ActiveDocument.Shapes(oShp.Name) because you end up back at the very same shape. This adds considerable load for no value whatsoever.
Think of the code being asked repeatedly: first select a document, now in that document look through the shapes and find the one called something, now look in that shape at its textframe, is it overflowing? If so, go to another document (which happens to be the same as the one you were just thinking of), look through the shapes until you find one that happens to have the same name as the shape you already know about. Now look at that new shape's alttext and see if it says 'shrink'. If so go to another document (which happens to be the same as the one you were previously thinking of), look through the shapes until you find one that happens to have the same name as the shape you already know about. Look in that shapes TextFrame and see if it is overflowing. If so etc etc etc
Look at the way my sample code was structured - there was a reason ActiveDocument.Shapes appears once only.

2. Avoid repagination whereever possible. If you change your view to Draft view, this may allow Word to work without repeated repaginations. Also the fact that your loop asks for an active page number 'probably' forces a repagination (how else can Word know the answer?) - do you get a speed improvement if you stop asking for that?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote