Save As File Format

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Save As File Format

Post by jstevens »

Does anyone have a reference to VBA code that will identiy the Excel Application Version (application.version) and perform a file "save as" using the version of Excel that opened the file.

As an example: A file was created with Excel 2003 and subsequently is opened by another user with Excel 2007. There are instances where some folks do not have Excel 2007; just Excel 2003. I know there is a conversion utility for Excel 2003 to read Excel 2007 files but they may not have the software installed.

Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save As File Format

Post by HansV »

Important: I modified the code below because the version I originally posted won't work (the constant for Excel 2007 should be 51 instead of 50 as I originally had. Sorry for the confusion!

Try something like this:

Code: Select all

Dim strFileName As String
strFileName = "Testing"
If Val(Application.Version) < 12 Then
  ' Excel 2003 or before
  ActiveWorkbook.SaveAs strFileName & ".xls", 56 '=xlExcel8
Else
  ' Excel 2007 or later
  ActiveWorkbook.SaveAs strFileName & ".xlsx", 51 '=xlOpenXMLWorkbook
End If
You can't use the constants xlExcel8 and xlOpenXMLWorkbook because they would cause an error in versions before Excel 2007, so I used their numeric values.
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Save As File Format

Post by Sundog »

Hans, very handy, and good input re constants in early versions. Thanks.
Sundog

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save As File Format

Post by HansV »

Please note that I modified my previous reply since it contained an error!
Best wishes,
Hans