-
Code to create Excel xls file doesn't work with Excel 2007
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
Similar Threads
-
Replies: 1
Last Post: 01-12-2006, 07:42 PM
-
By jase_dukerider in forum C++
Replies: 2
Last Post: 04-14-2005, 07:48 PM
-
By Chaitanya Marvici in forum ASP.NET
Replies: 6
Last Post: 07-21-2003, 09:15 AM
-
Replies: 8
Last Post: 01-09-2003, 10:42 PM
-
Replies: 0
Last Post: 07-08-2002, 11:37 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|