Speed of macros reduced to a snail pace

D

Dave Neve

Hi

I recently asked a question about two docs that use the same .dot as
reference to execute macros and install a toolbar.

One of the docs works very well while the other one (much longer table) has
become unusable due to the speed of execution

Today, I inserted a second table in the slow doc and the macros executed
right away.

So I have concluded that it is the length of the main table in the
problematic doc that is causing the problem and nothing else.

I have copied below one of the macros the speed of which seems to be
affected by the length of the table.

Can anyone help me to get around this problem as I can't wait one minute
each time for a macro to execute.

I selcet the word with the cursor before running the macro.

Thanks in advance

Dave Neve

Sub FallingLong()

Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range
j = 2

For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)

If Selection.Characters.Count <= 5 Then

lrange.Font.Size = 18
lrange.Font.Size = lrange.Font.Size - j
j = j + 2
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorSkyBlue

Else

lrange.Font.Size = 16
lrange.Font.Size = lrange.Font.Size - j
j = j + 1
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorSkyBlue

End If
Next i
Selection.Collapse Direction:=wdCollapseEnd

Selection.ExtendMode = False
Selection.Font.Reset

Call NextWordSelect

End Sub
 
W

Word Heretic

G'day "Dave Neve" <[email protected]>,

Don't iterate the characters collection. Instead, use a MoveStart to
move the start of your desired range along one character, and always
test .characters(1)

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Dave Neve reckoned:
 
K

Klaus Linke

Hi Dave,

And if it's long tables that are responsible for the slowness (which isn't
an issue with macros only, but also makes typing a pain):

It's pretty much the longest table(s) that determines the
speed/responsiveness. Many short tables are ok, one or several long tables
(spanning several tables) slow Word to a crawl.

With one large table, the responsiveness is about reciprocal to the table
length.

The only real solution is to split the longest tables. Setting the tables to
fixed width (rather than AutoFit to content/window) helps a bit, but not
much.

Greetings,
Klaus
 
H

Helmut Weber

Hi Dave,

and besides all other good advices,
see http://tinyurl.com/c5nq8
for range vs. selection in tables regarding speed.


Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Dave Neve

Hi

This answer interests me but I don't really understand it.

What do you mean by 'iterate' and how do you use 'move start'.

Finally, what does test characters (1) do and how/where do I incorporate it
into the macro?

Sorry but I can't write macros really, I can only just about manipulate them
into docs and tolbars

Thanks in advance
 
W

Word Heretic

G'day "Dave Neve" <[email protected]>,

For k= 1 to 10

K iterates from 1 to 10.



Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Dave Neve reckoned:
 

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