We help IT Professionals succeed at work.

Find and replace one word in Microsoft Documents With Delphi

iman_a_r
iman_a_r asked
on
2,292 Views
Last Modified: 2012-05-04
Hi all,
I Want an example to find and replace one word of text with the
TwordDocument Class or WordBasic.

Thanks for your help.
Comment
Watch Question

Manuel Lopez-MichelonePhD candidate
CERTIFIED EXPERT

Commented:
Hi
tell me if this what you need:

uses
     ComObj;   {se necesita para hacer OLE automation}

procedure TForm1.Button1Click(Sender: TObject);
//from word to richedit...
begin
  MsWord := GetActiveOleObject('Word.Basic');
  MsWord.EditSelectAll;
  MsWord.EditCopy;
  Form1.RichEdit1.PasteFromClipboard;
end;

procedure TForm1.Button2Click(Sender: TObject);
//from richedit to word...
begin
  MsWord := GetActiveOleObject('Word.Basic');
  Form1.RichEdit1.SelectAll;
  Form1.RichEdit1.CopyToClipboard;
  MsWord.EditSelectAll;
  MsWord.EditPaste;

end;

best regards
Manuel Lopez (lopem)

Commented:
d : TWordDocument;

  vFindText := source;
  vReplaceWith := target;
  vMatchCase := true;
  vMatchWholeWord := true;
  vReplace := wdReplaceAll;

  d.Range.Find.Execute( vFindText, vMatchCase, vMatchWholeWord, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, vReplaceWith, vReplace, EmptyParam, EmptyParam, EmptyParam, EmptyParam );

Author

Commented:
This code is that i need ,but it dose not work.
I dont know thats roson.

Author

Commented:
eugenem , if need any setting to work you'r code.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.