Uses Word2000, ComObj;
var Word_Handle,Doc_Handle:OleVariant;
try
Word_Handle:=GetActiveOleObject('Word.Application');
except
try
Word_Handle := CreateOleObject('Word.Application');
except
Exit;
end;
end;
Word_Handle.Visible := True;
Word_Handle.Documents.Open(filename);
Doc_Handle:=Word_Handle.Documents.Add(Template:=AppPath+'Database/Template.dot',NewTemplate:=False);
Word_Handle.ActiveDocument.SaveAs(FileName:='D:/aa/'+jdbh+'.doc',FileFormat:=wdFormatDocument,AddToRecentFiles:=False);
procedure ReplaceStr(SourceStr,DestStr:string;WordHandle:OleVariant);
begin
WordHandle.Selection.Find.ClearFormatting;
WordHandle.Selection.Find.Text :=SourceStr;
WordHandle.Selection.Find.Replacement.Text := DestStr;
WordHandle.Selection.Find.Execute(Replace:=wdReplaceAll);
end;