If you have more than 256 columns of data, try saving as a CSV file instead.
EDIT (after you stated it only happens if you click NO/CANCEL) =================
The
SaveAs
form will return a result (probably OK or CANCEL). What you need to do is use that return value, something like this:
string path = "";
if (excelWorkbook != null)
{
DialogResult result = excelWorkbook.SaveAs(...);
if (result == DialogResult.OK)
{
string path = @"D:\RiteFile\" + filename + ".xlsm";
}
excelApp.DisplayAlerts = false;
excelApp.UserControl = false;
excelWorkbook.Close();
excelApp.Workbooks.Close();
excelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
excelWorkbook = null;
excelApp = null;
if (!string.IsNullOrEmpty(path))
{
System.Diagnostics.Process.Start(path);
}
}
Keep in mind that I don't know for sure what the return type is, and the code above is merely an example.