PDA

View Full Version : Pasting in Word document is slowing down as the number of paste operations increases.



stranno
08-09-2013, 04:03 AM
Hi,
I create a mailinglist by pasting a sample letter (in a loop) into a new document as many times as necessary (if the list contains 50 letters, i paste the sample letter 50 times). After a sample letter is being pasted, variables (like name, address etc.) will be adapted via find and replace.

In order to keep the right format and page numbering (mentioned in the header) a section break is being inserted at the end of each letter. So far so good. But this proces is slowing down as the number of letters increases. For example processing 200 letters (4 pages a letter) takes 769 sec. I noticed that most of the time is being consumed by the pasting process (not the find and replace code).

my question is, is there an alternative way for pasting (thus using the clipboard). I tried to insert text from a variable in which i stored de example letter, but this method did result in format and page number errors. Maybe somebody knows how to prevent these errors. But i 'am not sure whether this method is faster than pasting.

And why is the pasting process slowing down as the number of pasted letters increases? regards, Stranno

Thierry76
08-10-2013, 04:27 AM
- did you disbladed office clipboard ? try Googling "SmartCutPaste" :
Word.Application.Options.SmartCutPaste = False
- avoid use clip board, read this first
oups I could'nt send you a link, according to the rule of this site :dunno, i will send it by PM

but more efficient, may be you should think coding different, did you try a real mailmerge and use word withevents ?
Word_MailMergeAfterRecordMerge, Word_MailMergeBeforeRecordMerge etc...

Let me know if it's help you...

ps to put a link in my reply I need 5 post, to send you a PM with a link i need 10, sorry
soo search by your own !
Avoid the Clipboard by Using Word's Range.FormattedText Property (by David Horowitz)

stranno
08-10-2013, 09:44 AM
Thanks for your tips Thierry76.
I will give it a try. Word is not my thing you know. But this time I couldn't avoid it. I'll let you know if it works for me. Thanks again.
Regards Stranno.

stranno
08-10-2013, 01:56 PM
By the way Thierry76, did you mean the article titled "Avoid the Clipboard by Using Word's Range.FormattedText Property" on the TechTrax site? is SmartCutPaste also available in Office 2003?
Regards, Stranno

Thierry76
08-11-2013, 10:34 AM
1°) Yes you find it... it's on TechTrax site :thumb
2°) SmartCutPaste is for Office XP to 2013 I think, but I am not 100% sure of that

I hope you don't forget my last advice, may be I shoud explain a little more, make a class of your code, add a var/Word with event, and You will have an event after each document/page merge, with few range.formattedtext use ... you will get a fast and flexible solution. According to my little experience, this is the fastest way...
Regards, Thierry

Thierry76
08-11-2013, 10:45 AM
try to find "Turn off (or customize) Word's Smart Cut and Paste (By Susan Harkins )" on TechRepublic site

SmartCutPaste is the special clipboard in Office apps, with historic possible use, you don't need this fonctionnaly in your code... and it could waste a lot of free RAM, and slow down your code...
By the way, because it's need only two lines to add on your code (one for disabled it, one for re-enabled it after), I think try this first will be my best tip...

stranno
08-11-2013, 12:43 PM
Hi Thierry76,
I can't get it done. I want to achive the same result as in the attached document. But without copy and paste operations. I tried to apply the range.FormattedText property, but the bla bla part (content of the letter) is (due to the sections grouping) being positioned on page 2. However this section grouping should be maintained.
By the way SmartCutPaste did not help. Strange enough the process became even slower.
The reason why i want to avoid copy and paste is that it is not very reliable but moreover it is too slow.
If you know how to handle this issue, would you please share it with me?
Regards and thanks in advance,
Stranno

SamT
08-11-2013, 06:08 PM
If this is for a Email letters, Use Mail Merge and Bookmarks for the variables,

If it's for paper letters, Again use Bookmarks or named ranges or whatever Word uses, But Print the letter on each iteration thru the loop of Names ,etc.

The Body of the Letter is a Constant. Reuse it, don't copy it. Changing a few variables will only take a few milliseconds that won't be noticeable next to the print time.

stranno
08-12-2013, 05:55 AM
Re-use!
That is exactly what i want. But then i can't manage to get the pages right.
If i use Copy and Paste it goes well. But if i use the Range.FormattedText Property to add the next sample letter to the mailinglist, the body of the letter (which is in section 2) ends up on page 2 instead of page 1 between the header and the footer. I have tried several things like the use of extra section breaks or the remove of section breaks. But this doesn't help.

The idee is as follows:
- There is a sample letter (lets say Sample_Letter.doc)
- VBA-code adds a new document (lets say Mailing_List.doc)
- Paste (but preferably otherwise) the content (and format) in Mailing_List.doc
- Change the key words (like name, address etc.) by means of find and replace.
- repeat these proceedings as often as the number of letters you have to compose.

The sections in the sample letter are as follows: On the first page there are 2 sections:
- Header and Footer in section 1 (first page different, see the attached .doc in previous Reply)
- Body of the letter is in section 2

I'm afraid i'm stuck and need some help.

Regards Stranno