Page 1 of 2

Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 10:26 am
by serge_girard
Hello,

I create a sheet and when the sheet is shown and the file allready exists I get an error: Error WINOLE/1007 (0x800A03EC): SAVEAS (DOS Error -2147352567) in case I decide NOT the overwrite the sheet.

Is there a way to avoid this error?

Thanks, Serge

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 11:18 am
by Rathinagiri
Can you check beforehand whether such file exists using

if file( cFile_Name )

else

endif

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 11:27 am
by serge_girard
Thanks Rathi,

But end-users might decide to NOT save and then same error occurs...

Serge

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 11:36 am
by Rathinagiri
Please send me some sample code. I shall try.

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 12:12 pm
by serge_girard
Rathi,

Take this little sample. Compile and run, then save the XLS.
Then press button again and then click NO to the XLS-question if you want to replace the (new) file.
Then error will occur!

Thanks if you can help.

Serge

Code: Select all

#include "hmg.ch"
 

FUNCTION MAIN()
/***************/

DEFINE WINDOW Form_1 ;
   AT 0,0 ;
   WIDTH  200 ;	 
   HEIGHT 200;	 
   TITLE ' xls' ;
   MAIN


   @ 10,10 BUTTON bt_test  ;
      CAPTION 'XLS' ;
      FONT 'Arial' SIZE 8      ;
      HEIGHT 86 ;    
      WIDTH  86 ;
      TOOLTIP 'XLS' ;
      ACTION Create_XLS()

END WINDOW

CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1

RETURN





FUNCTION Create_XLS()
/********************/
cFILE_NAME := 'C:\TEST\TEST.XLS'

oExcel1 := CreateObject( "Excel.Application" )
oExcel1:WorkBooks:Add()
 
oSheet1 := oExcel1:ActiveSheet()
oSheet1:Cells:Font:Name := "Arial"
oSheet1:Cells:Font:Size := 12
oSheet1:Cells( 1, 1 ):Value := "Email address"
oSheet1:Cells( 1, 1 ):Font:Size := 16
oSheet1:Cells( 1, 2 ):Value := "name 1"
oSheet1:Cells( 1, 2 ):Font:Size := 16
oSheet1:Cells( 1, 3 ):Value := "name 2"
oSheet1:Cells( 1, 3 ):Font:Size := 16

aARR  := {}
aadd(aARR, {'sg1@sg.be', 'name11','name21'}) 
aadd(aARR, {'sg2@sg.be', 'name12','name22'}) 
aadd(aARR, {'sg3@sg.be', 'name13','name23'}) 
aadd(aARR, {'sg4@sg.be', 'name14','name24'}) 
aadd(aARR, {'sg5@sg.be', 'name15','name25'}) 
aadd(aARR, {'sg6@sg.be', 'name16','name26'}) 
aadd(aARR, {'sg7@sg.be', 'name17','name27'}) 
aadd(aARR, {'sg8@sg.be', 'name18','name28'}) 
aadd(aARR, {'sg9@sg.be', 'name19','name29'}) 
nCEL  := 2

FOR i := 1 To LEN (aARR)
 
   oSheet1:Cells( nCEL, 1 ):Value := aARR [ i ] [ 1 ]
   oSheet1:Cells( nCEL, 2 ):Value := aARR [ i ] [ 2 ]
   oSheet1:Cells( nCEL, 3 ):Value := aARR [ i ] [ 3 ]

   oSheet1:Columns( 1 ):AutoFit()
   oSheet1:Columns( 2 ):AutoFit()
   oSheet1:Columns( 3 ):AutoFit()

   nCEL++

NEXT i

oSheet1:Cells( 1, 1 ):Select()
oExcel1:Visible := .T.
oSheet1:SaveAs(cFILE_NAME) 

 

RETURN


Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 1:52 pm
by pctoledo
The error only occurs if the file is already open

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 4:16 pm
by Clip2Mania
oExcel:DisplayAlerts := 0 ... ?

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Thu Oct 29, 2015 5:40 pm
by serge_girard
I'll try Erik!

Thx, Serge

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Fri Oct 30, 2015 4:57 pm
by jayadevu
Hi,

There is a simple solution:

Please try this before saving:
if !IsReadOnly(cXlFileNameWithFullPath)
oSheet1:SaveAs(cXlFileNameWithFullPath)
endif

FUNCTION IsReadOnly(cFile)
LOCAL nOpen := fopen(cFile,FO_EXCLUSIVE)
// if cFile is already open, nOpen will be -1
if nOpen != -1
FClose(nOpen)
endif
RETURN nOpen = -1

HTH,

Warm regards,

Jayadev

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Posted: Sat Oct 31, 2015 9:10 am
by serge_girard
Thanks Jayadev !

I will try.
Clipmania's oExcel:DisplayAlerts := 0 seems work also.

Thanks again, Serge