Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

MS Word Find/Replace Problem

Hi All,
I have a problem in that I am filling a word document with data from a database by replacing 'codes' with the data upon loading the word document. The problem that I have is that my documents are now very slow to open due to the fact that I am perfoming alot of find/replace procedures on the document, using the code below. Is there anyway of speeding up the find/replace procedure or any other suggestions on how we could replace codes in the document quicker?

many thanx for any help

Ben

myWordApp.Selection.find.ClearFormatting
myWordApp.Selection.find.replacement.ClearFormatting
    With myWordApp.Selection.find
        .Text = findtext
        .replacement.Text = replacetext
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
myWordApp.Selection.find.Execute Replace:=wdReplaceAll
0
BBaron
Asked:
BBaron
  • 2
  • 2
1 Solution
 
tampabay420Commented:
you should use MS Word's Form Fields, this would be much easier... i'll post an example... if you need more detail on how to use MS Words Form Fields with VBA, just ask?

     bookmark1 = "FormField_NAME"
       If wdApp.ActiveDocument.Bookmarks.Exists(bookmark1) Then

        wdApp.ActiveDocument.FormFields(bookmark1).Range.Text = crfdata(i).value

       
       End If
0
 
EDDYKTCommented:
I don't think your routine is slow because it is the fastest I can see. How many replaces you are going to do?

How long does it take?
If you command out this routine, will it speed up the time?
0
 
BBaronAuthor Commented:
Hi Guys,

thanx for the suggestion about the form fields tampabay420 Im going to investigate it a little more.. if you could perhaps email me on ben@brokerpartners.co.uk so I could ask more indepth questions and explain what Im doing a little me that would be great...

Eddykt,
the number of replaces depends on how many 'datacodes' I have in the template (user defined). so a basic document could be doing up to 100 finds..
It is definately the finds that is taking the time, I have traced it...
At some sites it can take up to a minute to open a word document and fill with data, so I obviously need to get it sorted..
0
 
BBaronAuthor Commented:
Hi Guys,

thanx for the suggestion about the form fields tampabay420 Im going to investigate it a little more.. if you could perhaps email me on ben@brokerpartners.co.uk so I could ask more indepth questions and explain what Im doing a little me that would be great...

Eddykt,
the number of replaces depends on how many 'datacodes' I have in the template (user defined). so a basic document could be doing up to 100 finds..
It is definately the finds that is taking the time, I have traced it...
At some sites it can take up to a minute to open a word document and fill with data, so I obviously need to get it sorted..
0
 
EDDYKTCommented:
You should not close the question and ask the question here

?->
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now