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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Automation - Test the version number before using SaveAs

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,333
FR
I just had a niggly problem, a user could not run a little applet that has been working for years and years, opening a .csv file formatting it and saving it as a nice .xls file (in 95/97 format).

The user was SURE he was running Office 2003, which the applet was certified to run on.

But he had both Office 2003 AND Office 2010... VFP was automating a copy of 2010 but presenting it in 2003.

Excel 2010 does not have the option to save files in 95/97 format (the underlying value in the SaveAs would be 43).

So, I had to do this:
Code:
OEXCEL = CREATEOBJECT("Excel.Application")
OEXCEL.Workbooks.Open(m.filename)
IF OEXCEL.VERSION < "12"
    OEXCEL.ActiveWorkbook.SaveAs( LEFT(m.filename,AT(".",m.filename))+"xls",43)
ELSE
    OEXCEL.ActiveWorkbook.SaveAs( LEFT(m.filename,AT(".",m.filename))+"xls",39)
ENDIF

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
That's not the only file format Excel has dropped, either. It no longer offers dbf for SaveAS(). (Although it still offers DIF and SYLK.)
 
OEXCEL = CREATEOBJECT("Excel.Application.11") would also work to open Excel 2003 despite of what's additionally installed, but your solution will also work with older Office Versions, which shouldn't be excluded of course, and with newer versions, using the file format 39.

Bye, Olaf.
 
Olaf,

That is a good idea.

What happens when Office2003 is not installed?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
If the version is not installed of course you get an error. About the same as if no excel at all is installed. So I could ask you the same question: What happens, if no excel is installed in your code? You don't put it in TRY..CATCH, so the normal error handling will run. If you do not handle the error, your app will show a error message and quit.

Bye, Olaf.
 
quite right, no excel no run.

it's kinda fundamental

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top