uses
ComObj;
procedure TForm1.FormCreate(Sender: TObject);
begin
OpenDialog1.Filter := 'TXT / DOC|*.txt;*.doc';
OpenDialog1.Options := [ofHideReadOnly, ofAllowMultiSelect, ofPathMustExist,
ofFileMustExist, ofEnableSizing];
end;
procedure TForm1.Button1Click(Sender: TObject);
const
wdFormatRTF = 6;
var
x: integer;
s: string;
Word1: Variant;
begin
try
Word1 := CreateOleObject('Word.Application');
except
raise exception.create('MS-Word ist nicht ansprechbar! ');
exit;
end;
Button1.enabled := false;
try
if OpenDialog1.execute then
begin
Screen.cursor := crHourglass;
for x := 0 to OpenDialog1.Files.count - 1 do
begin
s := ExtractFilename(OpenDialog1.Files[x]);
s := ChangeFileExt(s, '.rtf');
Word1.Documents.Open(OpenDialog1.Files[x]);
Word1.ActiveDocument.SaveAs(s, wdFormatRTF);
Word1.Documents.close;
end;
Word1.Quit;
end;
except
raise exception.create('Unerwarteter Fehler');
end;
Button1.enabled := true;
Screen.cursor := crDefault;
end;