Excel 2007 PIA saves as .xlsx with .xls extension

N

ndyguy

Background:
I have a development machine using Office 2007. I'm trying to update a
program that previously worked with Excel 2003 to also work with Excel 2007
(we haven't switched to 2007 yet). In order to get my 2007 machine to
compile the old program, I had to compile it on another development machine
with 2003, copy local the 2003 PIA's, and reference the local copies. In
that way it still works with Office 2003, but on a machine with 2007 PIA's it
redirects to 2007.

Here's my problem:
The program seems to work fine (opening, saving, closing, etc.). Excel
2007's settings are set to save files as 2003 xls. However, reopening the
file with Excel 2007 gives an error window saying "The file you are trying to
open, 'file.xls', is in a different format than specified by the file
extension" and if opened with 2003 it says "the file is not a recognizable
format." If in 2007 the file is saved, the error returns. If the file is
'save as' to xls or if the file extension is manually changed to xlsx the
error disappears. So it looks like Excel 2007 is saving the file as an xlsx
with a xls extension. Any ideas why this is happening?
 
C

Cindy M.

Hi Ndyguy,

Check the setting for the default save file format: Excel Options/Save

There was a very similar problem to this in the VSTO forum yesterday (for Word)
and it turned out that this was the cause.

Solution: Be very sure to set the FileFormat type in the SaveAs method. Don't
rely on the file extension to determine the file format.
Background:
I have a development machine using Office 2007. I'm trying to update a
program that previously worked with Excel 2003 to also work with Excel 2007
(we haven't switched to 2007 yet). In order to get my 2007 machine to
compile the old program, I had to compile it on another development machine
with 2003, copy local the 2003 PIA's, and reference the local copies. In
that way it still works with Office 2003, but on a machine with 2007 PIA's it
redirects to 2007.

Here's my problem:
The program seems to work fine (opening, saving, closing, etc.). Excel
2007's settings are set to save files as 2003 xls. However, reopening the
file with Excel 2007 gives an error window saying "The file you are trying to
open, 'file.xls', is in a different format than specified by the file
extension" and if opened with 2003 it says "the file is not a recognizable
format." If in 2007 the file is saved, the error returns. If the file is
'save as' to xls or if the file extension is manually changed to xlsx the
error disappears. So it looks like Excel 2007 is saving the file as an xlsx
with a xls extension. Any ideas why this is happening?


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
N

ndyguy

Hi Cindy,
I was thinking the same thing last night and the problem was the FileFormat
parameter of the SaveAs method. Apparently the only thing the Excel
Options/Save setting (which I tried with both xls and xlsx) has an affect on
when using Excel programmatically is attach a file extension.

A list of the FileFormat Enumeration can be found here:
http://msdn.microsoft.com/en-us/library/bb241279.aspx#

I wasn't able to differentiate the difference between some of them, but
these three allowed me to save as a 97-2003 format: xlAddIn, xlExcel7, and
xlWorkbookNormal.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top