How to increase speed of word macro

C

cc900630

I have a word macro that loops a SQL recorset, each time adding a row
to a table and writing some data , anything more than 30 rows and it
really slows down and the CPU fan kicks in - then I could literally
type the data in faster by hand. With 300 Rows it takes over 20 minutes
to finish!!

Any one know how to optimise this kind of macro ?

Thanks
 
C

cc900630

Also while this is happening the CPU Usage is only just above 50%, and
Winword uses only around 22,500K and 50% of the CPU.
 
J

Jonathan West

I would put the data into a tab-delimited string. Once all the data has been
put into the string, use the Insert method to put the string into the
document as text. Then apply the ConvertToTable method to the inserted text
to make a table out of it.

To make the string concatenation go even faster, I would recommend you use
Karl Peterson's CStringBuilder class
http://vb.mvps.org/samples/project.asp?id=StrBldr

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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