Discussion:
Word slow performance adding Table records.
(too old to reply)
mojo
2004-02-23 15:18:55 UTC
Permalink
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
Bryon
2004-02-23 17:31:07 UTC
Permalink
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
Jezebel
2004-02-23 20:58:44 UTC
Permalink
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.
Post by 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
Jay Freedman
2004-02-23 21:57:21 UTC
Permalink
The specific page on the mvps site is
http://word.mvps.org/FAQs/TblsFldsFms/FastTables.htm.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Post by 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
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.
Post by 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
Loading...