Error on oSheet1:SaveAs(cFILE_NAME)

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
serge_girard
Posts: 3308
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Error on oSheet1:SaveAs(cFILE_NAME)

Post 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
There's nothing you can do that can't be done...
User avatar
Rathinagiri
Posts: 5480
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post by Rathinagiri »

Can you check beforehand whether such file exists using

if file( cFile_Name )

else

endif
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3308
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post by serge_girard »

Thanks Rathi,

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

Serge
There's nothing you can do that can't be done...
User avatar
Rathinagiri
Posts: 5480
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post by Rathinagiri »

Please send me some sample code. I shall try.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3308
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post 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

There's nothing you can do that can't be done...
User avatar
pctoledo
Posts: 123
Joined: Wed Aug 25, 2010 10:45 am
Location: Araçatuba - SP - Brazil
Contact:

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post by pctoledo »

The error only occurs if the file is already open
Regards/Saludos,

Toledo

Clipper On Line
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post by Clip2Mania »

oExcel:DisplayAlerts := 0 ... ?
User avatar
serge_girard
Posts: 3308
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post by serge_girard »

I'll try Erik!

Thx, Serge
There's nothing you can do that can't be done...
jayadevu
Posts: 240
Joined: Tue May 19, 2009 7:10 am

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post 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
User avatar
serge_girard
Posts: 3308
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Error on oSheet1:SaveAs(cFILE_NAME)

Post by serge_girard »

Thanks Jayadev !

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

Thanks again, Serge
There's nothing you can do that can't be done...
Post Reply