?
Solved

MS Word Find/Replace Problem

Posted on 2003-02-27
5
Medium Priority
?
208 Views
Last Modified: 2010-04-07
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
Comment
Question by:BBaron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
tampabay420 earned 2000 total points
ID: 8033058
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8033086
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
 

Author Comment

by:BBaron
ID: 8033510
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
 

Author Comment

by:BBaron
ID: 8033749
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
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8034430
You should not close the question and ask the question here

?->
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question