Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save excel sheet into excel 95

Status
Not open for further replies.

Paco75

Programmer
Oct 11, 2001
239
US
Hi,

I use the import function to convert a excel file to dbf file. But it only works with excel 95 files. So if i have excel files from latest versions (97, 2003, 2007...) i have to manually save them in excel 95 files.

I there a way to save a excel file into another format programmatically?

thanks
 
Yep im sure if i save the file in 97-2003 and run the program i got a message saying that excel has stopped working and wil be closed.
 
well unless another trouble unknown to me is causing this error...
 
Paco said:
i got a message saying that excel has stopped working and wil be closed

That suggest you are not using IMPORT. The message looks like one generated by Excel itself.

Perhaps you could let us know exactly how you are going about this import.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Code:
MyFile = GETFILE("Excel *.xls:XLS","Import the excel file:","Import",0,"Choose the file to import")
IF NOT EMPTY(MyFile) THEN 
	IMPORT FROM JUSTFNAME(MyFile) TYPE XL8  && imports the XLS into a DBF
ENDIF
 
Paco, I just tried your code, using workbooks that were saved in 2007 and 2000. It worked fine in both cases.

However, you need to remove the JUSTFNAME(). VFP needs to know the full name plus extension, even though it knows it's TYPE XL8.

Furthermore, this command doesn't actually fire up Excel, so the message you saw must have been caused by something else.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Weird, here it does not work unless i save the excel file as Excel 5.0/95 Workbook :S
 
if i try with excel 2007 i got the following error:

"Microsoft Excel file format is invalid.
 
Is there a way to open and save the file in excel 95? even if it opens excel and close it it would be acceptable.
 
i mean in an automated way of course
 
Paco said:
if i try with excel 2007 i got the following error: "Microsoft Excel file format is invalid."

I told you earlier that you can't use the native VFP import methods with files saved in Excel 2007 or above. That applies even if you save it in 2007 format, or 97 - 2003 format, but not 95/5.0. Which leads to your next question:

Paco said:
Is there a way to open and save the file in excel 95?

Yes, you can do that through Automation, with all versions of Excel. Just call your workbook object's SaveAs method, passing the filename to save to, and the ID of the file format, which in this case happens to be 43. In other words:

Code:
* Assume loWorkbook is your workbook
loWorkbook.SaveAs("c:\data\myworkbook.xls", 43)

* Then close Excel in the normal way

Obviously, that's not a complete bit of working code, but you should be able to figure the rest of it out for yourself.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I found this link that helped me in case someone want to save in another excel format (just as with excel save as)
[URL unfurl="true"]http://fox.wikis.com/wc.dll?Wiki~ExcelAutomation[/url]

Here is my code
Code:
MyFile = GETFILE("Excel *.xls:XLS,XLSX","Importer le fichier excel:","Importer",0,"Choisissez le fichier à importer")

MyNewFile = JUSTPATH(MyFile)+"\New"+JUSTFNAME(MyFile)

oExcel = CreateObject("Excel.Application")
if vartype(oExcel) != "O"
  * could not instantiate Excel object
  * show an error message here
  return .F.
ELSE 
	oWorkbook = oExcel.Application.Workbooks.Open(MyFile)
	if val(oExcel.Version) > 7
	    oWorkbook.SaveAs(MyNewFile, 39) && xlExcel5
	else
	    oWorkbook.SaveAs(MyNewFile)
	ENDIF
	oExcel.quit() && Close excel instance
ENDIF
oExcel = .Null. && To avoid leaving open excel instance...

IF NOT EMPTY(MyNewFile) THEN 
	IMPORT FROM (MyNewFile) TYPE XL8  && imports the XLS into a DBF
ENDIF
 
I seem to use the wrong value for excel5 files... you seem to say it is 43 not 39... but it solves the problem i got previously... maybe the excel was having bad formatting and saving it corrected it. Anyways, thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top