We have several reports in our VB program that creates a tab delimited text file and then creates and opens an Excel worksheet from this. It has always worked created. However now some of our users has installed Excel 2007 and now it doesn't work. It errors on the SaveAs. I've installed Office 2007 to recreate the problem.

Here's the VB code:

Dim objExcelApp As Excel.Application
Dim objExcelSheet As Excel.Worksheet
Dim objExcelWKBook As Excel.Workbook

'code here that creates the tab delimited text file - strFileNametxt

Set objExcelApp = Excel.Application

objExcelApp.Visible = False
objExcelApp.Workbooks.Open strFileNametxt
Set objExcelWKBook = objExcelApp.ActiveWorkbook
Set objExcelSheet = objExcelApp.ActiveSheet

'resize the columns
For intLoop = 1 To intFieldCount Step 1
objExcelSheet.Columns(intLoop).EntireColumn.AutoFit
Next intLoop

'save as a spreadsheet
ActiveWorkbook.SaveAs FileName:=strFileNamexls, _
FileFormat:=xlExcel9795, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

It hits the above line and boom! I had even made sure what was in strFileNamexls had an xlsx extension but it didn't make any difference. I think the problem may be FileFormat:=xlExcel9795 but I have no idea what to put instead. Also this has to be backward compatible so is there a way through code to determine what version of Excel they have?

Thanks