Board index » delphi » How to : Close an Excel OLe Object without saving the file ...

How to : Close an Excel OLe Object without saving the file ...

My source :

var
   monexcel: OLEVariant;
   ch_temp:string;
begin
  {* Appel d'exel *}
  try
    monexcel := CreateOLEObject( 'Excel.Application' );
  except
    MessageDlg( 'Cannot start Excel.', mtError, [mbOk], 0 );
    Exit;
  end;
  {* edit1.text + edit2.text > edit3.text via Excel *}
  ch_temp:='=' + edit1.text + ' + ' + edit2.text;
  try
    monexcel.Visible := false;
    monexcel.Workbooks.Add;
    {monexcel.ActiveCell.FormulaR1C1:=ch_temp;}
    monexcel.Range['A1','A1'].Value:=edit1.text;
    monexcel.Range['A2','A2'].Value:=edit2.text;
    monexcel.Cells[3,1].Value :='=SUM(R[-2]C:R[-1]C)';
    edit3.text := monexcel.Range['A3','A3'].Value;
  finally
    monexcel.Workbooks.Close;
    monexcel.Quit;
    monexcel:= unassigned;
  end;

As you can test and see, when I call method Workbooks.Close or Quit, it
opens a "Save File " dialog box. How can I overpassed it ? (should be a
boolean flag but don't know where I had to add it).

Regards, Christophe Berg

 

Re:How to : Close an Excel OLe Object without saving the file ...


Salut Christophe,

I don't know about Excel, but I can tell you how to do this in Word.
Perhaps (hopefully) they are to be used in the same manner ...

Here's what I would be doing for  Word :

 SaveChanges : OleVariant;

  SaveChanges :=  False;
  Variant(WinWord).Quit(SaveChanges);

Hope this helps,

bient?t,

Rudi

Christophe Berg schrieb:

Quote
> My source :

> var
>    monexcel: OLEVariant;
>    ch_temp:string;
> begin
>   {* Appel d'exel *}
>   try
>     monexcel := CreateOLEObject( 'Excel.Application' );
>   except
>     MessageDlg( 'Cannot start Excel.', mtError, [mbOk], 0 );
>     Exit;
>   end;
>   {* edit1.text + edit2.text > edit3.text via Excel *}
>   ch_temp:='=' + edit1.text + ' + ' + edit2.text;
>   try
>     monexcel.Visible := false;
>     monexcel.Workbooks.Add;
>     {monexcel.ActiveCell.FormulaR1C1:=ch_temp;}
>     monexcel.Range['A1','A1'].Value:=edit1.text;
>     monexcel.Range['A2','A2'].Value:=edit2.text;
>     monexcel.Cells[3,1].Value :='=SUM(R[-2]C:R[-1]C)';
>     edit3.text := monexcel.Range['A3','A3'].Value;
>   finally
>     monexcel.Workbooks.Close;
>     monexcel.Quit;
>     monexcel:= unassigned;
>   end;

> As you can test and see, when I call method Workbooks.Close or Quit, it
> opens a "Save File " dialog box. How can I overpassed it ? (should be a
> boolean flag but don't know where I had to add it).

> Regards, Christophe Berg

Re:How to : Close an Excel OLe Object without saving the file ...


Before you call monexcel.Quit, you can call monexcel.DisplayAlerts := False

Quote
Rudolf Ziegaus wrote:
> Salut Christophe,

> I don't know about Excel, but I can tell you how to do this in Word.
> Perhaps (hopefully) they are to be used in the same manner ...

> Here's what I would be doing for  Word :

>  SaveChanges : OleVariant;

>   SaveChanges :=  False;
>   Variant(WinWord).Quit(SaveChanges);

> Hope this helps,

> bient?t,

> Rudi

> Christophe Berg schrieb:

> > My source :

> > var
> >    monexcel: OLEVariant;
> >    ch_temp:string;
> > begin
> >   {* Appel d'exel *}
> >   try
> >     monexcel := CreateOLEObject( 'Excel.Application' );
> >   except
> >     MessageDlg( 'Cannot start Excel.', mtError, [mbOk], 0 );
> >     Exit;
> >   end;
> >   {* edit1.text + edit2.text > edit3.text via Excel *}
> >   ch_temp:='=' + edit1.text + ' + ' + edit2.text;
> >   try
> >     monexcel.Visible := false;
> >     monexcel.Workbooks.Add;
> >     {monexcel.ActiveCell.FormulaR1C1:=ch_temp;}
> >     monexcel.Range['A1','A1'].Value:=edit1.text;
> >     monexcel.Range['A2','A2'].Value:=edit2.text;
> >     monexcel.Cells[3,1].Value :='=SUM(R[-2]C:R[-1]C)';
> >     edit3.text := monexcel.Range['A3','A3'].Value;
> >   finally
> >     monexcel.Workbooks.Close;
> >     monexcel.Quit;
> >     monexcel:= unassigned;
> >   end;

> > As you can test and see, when I call method Workbooks.Close or Quit, it
> > opens a "Save File " dialog box. How can I overpassed it ? (should be a
> > boolean flag but don't know where I had to add it).

> > Regards, Christophe Berg

--
**********************************************************
ICON 99 is coming to PhilaDELPHIa
July 17-21
http://www.inprise.com/icon99/
-
CORBA Essentials returns to New York !
February 15/16
http://www.inprise.com/events/seminars/
http://www.inprise.com/events/seminars/schedule.html
-
Delphi World Tour
March 2-5
http://www.inprise.com/events/
**********************************************************

  sstrool.vcf
< 1K Download

Other Threads