Doc: TWordDocument;
....
procedure TMain.ReplaceBtnClick(Sender: TObject);
var
temp, SearchText, ReplaceText, All: OleVariant;
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, forward, wrap, format, replacewith, replace,
matchkashida, matchdiacritics, matchalefhamza, matchcontrol: olevariant;
TextRange: Range;
i: byte;
begin
TextRange := Doc.Content;
findtext := 'name';
replacewith := '张三';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
forward := true;
wrap := wdFindContinue;
format := false;
Replace := true;
i := 0;
while TextRange.find.execute(findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms,
forward, wrap, format, replacewith, replace, matchkashida,
matchdiacritics, matchalefhamza, matchcontrol)
do begin
inc(i);
end;
end;
Doc.PrintPreview; //打印预览
doc.ClosePrintPreview; //关闭打印预览
doc.printout;