Link to home
Start Free TrialLog in
Avatar of iman_a_r
iman_a_r

asked on

Find and replace one word in Microsoft Documents With Delphi

Hi all,
I Want an example to find and replace one word of text with the
TwordDocument Class or WordBasic.

Thanks for your help.
Avatar of Manuel Lopez-Michelone
Manuel Lopez-Michelone
Flag of Mexico image

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)
Avatar of eugenem
eugenem

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 );
Avatar of iman_a_r

ASKER

This code is that i need ,but it dose not work.
I dont know thats roson.
eugenem , if need any setting to work you'r code.
ASKER CERTIFIED SOLUTION
Avatar of eugenem
eugenem

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial