MSword search from Delphi

Giganews Newsgroups
Subject:MSword search from Delphi
Posted by: Papas Jim (dp…@softwaypro.gr)
Date:Tue, 19 Jan 2010

Hi,
In my Delphi prog,  I use OLE to search (forwards only, no wrap, with
wildcards) a certain portion of a Word doc for specific words and replace
them with some text with following code :
searchString := someTextToFind; // includes wildChars
repeat
        With  searchRange.Find do begin
                notFound := TRUE;
            ClearFormatting;
        Execute(searchString,emptyParam,emptyParam,OLETRUE,emptyParam,
                        emptyParam,emptyParam,emptyParam,emptyParam,emptyParam,
                        emptyParam,emptyParam,emptyParam,emptyParam,emptyParam);
            if found then begin
                    notFound := FALSE;
                    searchRange.Text :=aReplacementText;
                    searchRange.Start := searchRange.End_;
                end;
until notFound;
Even the searchRange is a portion of the document, the searching scans whole
the document. Why ?
After a match, the range has its start/end_ same as the founded word and I
have to do  start =end_ to continue until no matches anymore.
Without start =end_ the searching terminates,  but  with this, keeps
searching beyond the portion I want.
Somebody can help me please ?
I don't know VBA so I cant set a var type range to hold a copy of 2 or 3
doc's portions. Any range I set, affects/affected the document's content so
I use clipboard but it keeps only the last one copy. What can I do for this
?

TIA

Replies