PDA

View Full Version : Word VBA Find & Replace



senthilkumar
03-30-2009, 04:33 AM
Hi,

I want to find and replace in the given document. My input is in database in the form of FindPattern, ReplacePattern and Wildcard usage(true/false). I have to read the database information and store it an array. Using For loop i will execute the find and replace one by one. This is working fine for documents having less pages (<100 pages). But I try to execute this for more no. of pages then the execution is vely slow and taking more time to process. Is there any solution for this?

Set rngProcess = ActiveDocument.Range
For iCnt = 0 To UBound(sFindPattern)
With rngProcess.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Text = sFindPattern(iCnt) 'find pattern
.Replacement.Text = sReplacePattern(iCnt) 'replace pattern
.MatchWildcards = sWildCards(iCnt) 'wildcard value
.Execute Replace:=wdReplaceAll
End With
Next iCnt

regards,
Senthil. S :banghead:

macropod
03-30-2009, 05:49 AM
Hi senthilkumar,

You could try turning off screen updating, auto-saves & background repagination (you may need to use Normal view), plus disabling table auto-fitting.

senthilkumar
03-30-2009, 06:23 AM
Hi macropod,

senthilkumar
03-30-2009, 06:24 AM
Hi macropod,

Thanks for your reply. As I am not aware of that can you please try to explain me by giving code samples.

Regards,
Senthil. S

geekgirlau
04-01-2009, 06:12 PM
Dim intSave As Integer


intSave = Options.SaveInterval
Options.SaveInterval = 0
Options.Pagination = False
Application.ScreenUpdating = False

' your code here

Options.SaveInterval = intSave
Options.Pagination = True
Application.ScreenUpdating = True

macropod
04-01-2009, 06:28 PM
Hmm,

I wonder what became of my reply of 31 March ...

geekgirlau
04-01-2009, 07:42 PM
Maybe you were hit by an early April Fools Day - we Aussies get there before nearly anyone else!

senthilkumar
04-07-2009, 09:35 PM
Hi macropod,

senthilkumar
04-07-2009, 09:37 PM
Hi macropod,

Sorry yaar. I was hospitalised last week. That is thr reason for not replying. I will try this and Let us any improvement will be there in performance.

Thanks,
Senthil. S

senthilkumar
04-12-2009, 10:24 PM
Hi macropod,

I have tried your suggestion. But still it is taking the same time for executing the find patterns.

Thanks,
Senthil. S

macropod
04-12-2009, 11:40 PM
Hi senthilkumar,

There is a limit as to how fast you can process any document. One has to expect things to slow down with > 100 pages.

Paul_Hossler
04-13-2009, 03:57 PM
senthilkumar

How many Find and Replaces in your loop?

Also try putting


ActiveDocument.UndoClear


right before your Next iCnt to clear the UnDo cache

Let me know if it helps

Paul

fumei
04-14-2009, 10:34 AM
Hi Paul, that is an interesting suggestion. I am curious to hear if adding that makes any difference. I had never thought of the time/processing involved with the caching of actions into Undo. Makes sense though, as possibly hundreds of actions will indeed add processing through Undo.

Paul_Hossler
04-14-2009, 12:29 PM
There used to be a way to turn off UnDo, but AFAIK it's not available in later versions of Word

Paul