- Dec. 22, 2013
Excel can handle a lot of different file formats. Throughout the years a number of file formats have been in use. Just think of .xls, .xlsx, .xlsb, all kinds of text file formats, … The usual .xls format that we used to know from Excel versions prior to Excel 2007 has been replace in Excel 2007 with 2 file formats that became popular since that time:
- .xlsx format for Excel 2007/2010/2013 files without macro procedures
- .xlsm format for Excel 2007/2010/2013 files with macro procedures
A spreadsheet created in Excel can be saved under a multitude of file formats. Since Excel 2007, PDF is part of the supported file formats and you do not need third-party software to save as a PDF file. Below in this article you can find a big number of choices that you have when you do File > Save As….
|Excel Workbook||xlsx||Standard file format in Excel 2007/2010/2013, based on XML. No macro procedures!|
|Excel Macro-Enabled Workbook||xlsm||file format in Excel 2007/2010/2013, based on XML. Allows macro procedures toe.|
|Excel Binary Workbook||xlsb||Binary file format in Excel 2007/2010/2013.|
|Excel Template||xltx||Standard file format in Excel 2007/2010/2013 for a Template. No macro procedures!|
|Excel Macro-Enabled Template||xltm||file format in Excel 2007/2010/2013 for a Template. Allows macro procedures toe.|
|Excel 97-2003 Workbook||xls||Excel 97-2003 binary file format|
|Excel 97-2003 Template||xlt||Excel 97-2003 binary file format for a Template|
|Microsoft Excel 5.0/95 Workbook||xls||Excel 5.0/95 binary file format|
|Excel Add-In||xlam||Standard file format in Excel 2007/2010/2013, based on XML, ffor an Add-In.|
|Excel 97-2003 Add-In||xla||Excel 97-2003 binary file format for an Add-In|
|Formatted Text (Space delimited)||prn||Saves as an space-delimited file format|
|Text (Tab delimited)||txt||Saves as a tab-delimited text file for Windows (**)|
|Text (Macintosh)||txt||Saves as an tab-delimited text file for Macintosh (**)|
|Text (MS-DOS)||txt||Saves as an tab-delimited text file for MS-DOS (**)|
|Unicode Text||txt||Saves as Unicode text (*)|
|CSV (Comma delimited)||csv||Saves as a comma-delimited text file for Windows (**)|
|CSV (Macintosh)||csv||Saves as a comma-delimited text file for Macintosh (**)|
|CSV (MS-DOS)||csv||Saves as a comma-delimited text file for MS-DOS (**)|
|DIF (Data Interchange Format)||dif||Saves as the Data Interchange file format|
|SYLK (Symbolic Link)||slk||Saves as the Symbolic Link file format|
(**): Tabs, linebreaks and other characters are interpret correctly.
|PDF is a file format with a fixed layout that allows a file to retain its intended layout when it is viewed or printed|
|XPS Document||xps||XPS has the same objective as PDF, yet it is a different file format|
|OpenDocument Spreadsheet||ods||The OpenDocument Spreadsheet file format is a version of the OpenDocument Format (ODF) v1.1|
|XML Spreadsheet 2003||xml||The XML Spreadsheet 2003 file format|
|XML Data||xml||The XML Data file format|
|Single File Web Page||mht / mhtml||Saves (part of) a file as a Web page, including the underlying files and folders|
|Web Page||htm / html||Saves (part of) a file as a Web page, including the underlying files embedded int he Web page|
You can save a workbook or worksheet with above-mentioned file formats. How can we do this? Manually and using code.
Excel allows to recognize the file format of opened files. So you can detect whether the active workbook is an Excel 2007/2010/2013 file format without macro procedures (.xlsx extension). Write in the Immediate Window and press Enter:
? ActiveWorkbook.FileFormat = xlOpenXMLWorkbook
This results in True or False. Alternatively:
? ActiveWorkbook.FileFormat = 56
Each file format has its own number and name, that you can read with the FileFormat property in VBA. In the example above we test if the value for the FileFormat property for the active workbook coincides with the Excel constant xlOpenXMLWorkbook, which can be used in a short way as number 56. Question: How do you know the FileFormat constant for a certain FileFormat? Look in the handy tables below. The first table shows the constants with which a file can be saved in Excel 2007/2010/2013.
|File format||Extension||File Format name||File Format number|
|Excel Workbook||xlsx||xlOpenXMLWorkbook / xlWorkbookDefault||51|
|Excel Macro-Enabled Workbook||xlsm||xlOpenXMLWorkbookMacroEnabled||52|
|Excel Binary Workbook||xlsb||xlExcel12||50|
|Excel Macro-Enabled Template||xltm||xlOpenXMLTemplateMacroEnabled||53|
|Excel 97-2003 Workbook||xls||xlExcel8||56|
|Workbook normal||xls||xlNormal / xlWorkbookNormal||-4143|
|Excel 97-2003 Template||xlt||xlTemplate / xlTemplate8||17|
|Microsoft Excel 5.0/95 Workbook||xls||xlExcel5||39|
|Excel 97-2003 Add-In||xla||xlAddIn / xlAddIn8||18|
|Formatted Text (Space delimited)||prn||xlTextPrinter||36|
|Text (Tab delimited)||txt||xlTextWindows||20|
|Current Platform Text||txt||xlCurrentPlatformText||-4158|
|CSV (Comma delimited)||csv||xlCSV||6|
|DIF (Data Interchange Format)||dif||xlDIF||9|
|SYLK (Symbolic Link)||slk||xlSYLK||2 / 10|
|XML Spreadsheet 2003||xml||xlXMLSpreadsheet||46|
|Single File Web Page||mht / mhtml||xlWebArchive||45|
|Web Page||htm / html||xlHtml||44|
(**) use: ExportAsFixedFormat with Type = xlTypeXPS (constant 1)
For example, use in a macro procedure:
ActiveWorkbook.SaveAs FileName:="C:\MyFile", FileFormat:=xlOpenXMLWorkbook
Excel saves the active workbook as MyFile.xlsx on your C-drive. You do not need to add .xlsx yourself. With the shorthand notation 56:
ActiveWorkbook.SaveAs FileName:="C:\MyFile", FileFormat:=56
To save the active workbook as PDF or XPS:
ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:="C:\MyFile" 'or ActiveWorkbook.ExportAsFixedFormat Type:=xlTypeXPS, FileName:="C:\MyFile"
For those of you who prefer short and concise code (or, who are lazy):
ActiveWorkbook.ExportAsFixedFormat 0, "C:\MyFile" 'or ActiveWorkbook.ExportAsFixedFormat 1, "C:\MyFile"
Instead of the active workbook, any (valid) reference to a workbook is possible. Next to the File Format names and numbers above, there are still a number of others. As far as I know, however, you cannot save a workbook under these additional file formats in Excel 2007/2010/2013, but you can open such file formats in Excel and subsequently ask the type of file (see above for code examples). The last table below demonstrates these file formats; oftentimes these are older, deprecated, file formats.
|File format||File Format name||File Format number|
To end this blod article, here is a code snippet that I used to save a workbook under different file formats. That way, I could assess what works in Excel 2007/2010/2013 and what does not work.
Sub InvestigateFileFormat()' Wim Gielis ' https://www.wimgielis.comOn Error Resume Next Application.DisplayAlerts = False For i = 1 To 60 With Workbooks.Add .SaveAs Filename:="C:\" & Format(i, "00"), FileFormat:=i .Close End With Next Application.DisplayAlerts = TrueEnd Sub
Right, this blog article does not prove to be the mose amusing article on my website, but it is a handy overview article. Me myself, I regularly consult this page.