Uli Gerhardt
Uli Gerhardt

Reputation: 14001

Excel automation: Get a reasonable file format/extension for saving

In our Delphi app we automate MS Excel 2007 to generate and save a xls/xlsx file. How should we go about choosing a file format and extension for the generated file?

Hardcoding some values (e.g. xlOpenXMLWorkbook and .xlsx) doesn't work if the user has an older version of Excel installed. Not specifying a format probably works for older versions too (we're checking this right now) but leaves the question what the correct extension is. E.g. using .xls under Excel 2007 results in a XLSX file with wrong extension which leads to complaints when you open it in Excel.

Upvotes: 0

Views: 283

Answers (1)

SeanC
SeanC

Reputation: 15923

omit extension AND format:

activeworkbook.SaveAs "fred"

will save the file as the appropriate type, and supply the extension too. The file will be fred.xlsx in 2007+ and fred.xls in previous versions.

Upvotes: 1

Related Questions