Word slow performance adding Table records.

M

mojo

I need someone to run a test for me. This simple loop causes the performance
to degregate as the number of records added increase.

VBA - Word 2003

Create a Word doc.
Create a table with 10 or more columns.
Insert the loop below as a new module.
Run the macro.

What I see in the status field is rapid additions initially, then a visable
decrease in speed.

Anyone know why?

Public Sub amain
Dim maxrow as integer
Dim r as integer

Set myTable = ActiveDocument.Tables(1)

maxrow = 500
While r <= maxrow
StatusBar = "Please Wait - Writing Data Record " & r & " of " &
maxrow & " --|"
myTable.Rows.Add
r = r + 1
Wend
End Sub

Thanks,
MoJo
 
B

Bryon

I didn't test your code below, but I am having the same problem when running a macro that applies formatting to a table. Initially when the macro starts, it works at 'expected' speeds but, as it gets farther and farther down through the table each line of code gets slower and slower. I noticed that lines of code that refer to a Cell or Row object are the lines that are causing the performane problem.

I have tried turning off ScreenUpdating until after the macro is over. Didn't work

I have tried setting up objects instead of referring through objects (i.e. Set theCell = Tables(1).Cell(1,1)) Didn't work

I am running out of possible solutions

Bryon

----- mojo wrote: ----


I need someone to run a test for me. This simple loop causes the performanc
to degregate as the number of records added increase

VBA - Word 200

Create a Word doc
Create a table with 10 or more columns
Insert the loop below as a new module
Run the macro

What I see in the status field is rapid additions initially, then a visabl
decrease in speed

Anyone know why

Public Sub amai
Dim maxrow as intege
Dim r as intege

Set myTable = ActiveDocument.Tables(1

maxrow = 50
While r <= maxro
StatusBar = "Please Wait - Writing Data Record " & r & " of "
maxrow & " --|
myTable.Rows.Ad
r = r +
Wen
End Su

Thanks
MoJ
 
J

Jezebel

Word's table-handling 'engine' is a dog. Doa Google for any number of
articles on this. It slows down as the table gets longer. A couple of
techniques that will speed things up:

1) add all the rows at once (rather than one at a time, as your code does it
currently). If you're creating the table from data, construct the table in
memory then paste it in one action.

2) avoid large tables. Since the table has to split for the page break
anyway, create it separate table for each page.

One of the MVPs has researched this in detail ... try their site.
 

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