Ver Mensaje Individual
  #21  
Antiguo 06-10-2014
Avatar de fjcg02
[fjcg02] fjcg02 is offline
Miembro Premium
 
Registrado: dic 2003
Ubicación: Zamudio
Posts: 1.410
Reputación: 22
fjcg02 Va camino a la fama
Retroalimentando el problema.

He hecho una prueba simple.
1.- Programa simple que invoca a excel y crea un archivo CON SERVERS, finalmente se cierra de forma automática.

Código Delphi [-]
...
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    EApp: TExcelApplication;
    EWs: TExcelWorksheet;
    EWb: TExcelWorkbook;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
...

procedure TForm1.FormCreate(Sender: TObject);
begin
EApp.Connect;
EApp.Visible[0] := True;

EWb.ConnectTo(EApp.Workbooks.Add(EmptyParam,0));

EWb.ConnectTo(EApp.Workbooks.Add(EmptyParam,0));
EWs.ConnectTo(EApp.Sheets[1] as _WorkSheet);

EWb.SaveAs(ExtractFilePath( Application.ExeName ) + Edit1.Text,
                              -4143 {51}, emptyParam , emptyParam, false, false,
                              1, emptyParam, false, emptyParam, emptyParam,
                               emptyParam, 0);
EApp.Quit;
EApp.Disconnect;
Application.Terminate;
end;

end.

2.- Programa simple que invoca a excel y crea un archivo con automatización, finalmente se cierra de forma automática.
Código Delphi [-]
procedure TForm1.FormCreate(Sender: TObject);
var
   Excel : OleVariant;
   WrkB, WrkS : OleVariant;
begin
  try
     try
        Excel := GetActiveOleObject('Excel.Application');
     except
        Excel := CreateOleObject('Excel.Application');
     end;
     Excel.DisplayAlerts := True;
     Excel.Visible := True;
     //WrkB := Excel.Workbooks.Open(ExtractFilePath(Application.ExeName) + Edit1.Text);
     WrkB := Excel.Workbooks.Add;
     WrkB.SaveAs(ExtractFilePath(Application.ExeName) + Edit1.Text);
   finally
     Excel.Quit;
     Excel := Unassigned;
     WrkS := Unassigned;
     WrkB := Unassigned;
  end;
Application.Terminate;
end;

LOS DOS FUNCIONAN cuando los programo como tareas planificadas.

Ya no sé por dónde pegarle, estoy más confundido que antes...

Saludos
__________________
Cuando los grillos cantan, es que es de noche - viejo proverbio chino -
Responder Con Cita