Home » excel » vb.NET SaveAs not saving all Excel data

vb.NET SaveAs not saving all Excel data

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a very strange issue that I cannot seem to find an answer to online.

I have a VB.NET application that creates an Excel of data (roughly 42,542 rows in total) and the saves the file to a folder location & opens it on screen for the user.

The onscreen version & folder version is only showing 16,372 rows of data like it is being cut off.

When I go through debug I can see all the rows are being added & if I save manually in debug all the rows save. Some data seems to get lost on the system save.

I am taking data from 4 record sets & writing each set one after the other with specific headers for each block on the Excel sheet.

My save line is:

xlWBook.SaveAs(Filename:=sFileName, FileFormat:=Excel.XlFileFormat.xlExcel7)

Would anyone please have any ideas as to what this might be?

How to&Answers:

Older version of Excel only support 16,384 rows per worksheet. You are saving as Excel7 (which is Excel 95) and has this limitation:

See here for a summary of sizes per version:

https://superuser.com/questions/366468/what-is-the-maximum-allowed-rows-in-a-microsoft-excel-xls-or-xlsx

Change your code to another format, See here for all the allowed formats: XlFileFormat Enumeration

However the file format is actually an optional argument in the SaveAs method, so you could leave it off altogether: “For an existing file, the default format is the last file format specified; for a new file, the default is the format of the version of Excel being used.”

Source: WorkBook.SaveAs Method