uses comobj;
var
xcl, wkb: OleVariant;
procedure TForm1.Button2Click(Sender: TObject);
var anz: integer;
function before(welche, vorwelche: integer): boolean;
begin
if (welche < 1) or (vorwelche > anz) then result := false
else begin
wkb.Sheets[welche].Move(wkb.Sheets[vorwelche]);
result := true;
end;
end;
function after(welche, hinterwelche: integer): boolean;
begin
if (welche < 1) or (hinterwelche > anz) then result := false
else begin
if hinterwelche < anz then
wkb.Sheets[welche].Move(wkb.Sheets[succ(hinterwelche)])
else begin
wkb.Sheets[welche].Move(wkb.Sheets[hinterwelche]);
wkb.Sheets[hinterwelche].Move(wkb.Sheets[pred(hinterwelche)]);
end;
result := true;
end;
end;
begin
xcl := createOleObject('Excel.Application');
wkb := xcl.workbooks.add;
anz := wkb.Sheets.count;
xcl.visible := true;
if not after(1, 3)
then showmessage('Falsche Sheet-Zahl');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if not VarIsEmpty(xcl) then xcl.quit;
end;