title: How do I save an Excel file without getting a format warning when opening, using C# and Excel 2010
body: <p>I'm using Excel 2010.
  I'm trying so save my excel file, with this code. 
  It does save a .xls file, but when I open the file I get this message: </p>
  
  <blockquote>
    <p>The file you are trying to open, 'tre.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a thrusted source before opening the file. Do you want to open the file now?</p>
  </blockquote>
  
  <p>If I press <code>yes</code>the file opens. But what do I need to get rid of this format-popup?</p>
  
  <p>My code:</p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  using ExcelAddIn1.Classes;
  using ExcelAddIn1.Classes.Config;
  using Microsoft.Office.Interop.Excel;
  using Application = Microsoft.Office.Interop.Excel.Application;
  using System.Runtime.InteropServices;
  
  
  private void Foo(object sender, EventArgs e)
  {
      SaveFileDialog saveFileDialog = new SaveFileDialog();
      saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
      saveFileDialog.FilterIndex = 0;
      saveFileDialog.RestoreDirectory = true;
      saveFileDialog.CreatePrompt = true;
      saveFileDialog.FileName = null;
      saveFileDialog.Title = "Save path of the file to be exported";
  
      if (saveFileDialog.ShowDialog() == DialogResult.OK)
      {
          // Save. 
          // The selected path can be got with saveFileDialog.FileName.ToString()
          Application excelObj = 
              (Application)Marshal.GetActiveObject("Excel.Application");
          Workbook wbook = excelObj.ActiveWorkbook;
          wbook.SaveAs(saveFileDialog.FileName, XlFileFormat.xlWorkbookDefault, 
              Type.Missing, Type.Missing, false, false, 
              XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, 
              Type.Missing, Type.Missing, Type.Missing);
          wbook.Close();
      }
  }
  </code></pre>
  
  <p>When I save in excel in the normal way I get "Book1.xlsx", that have no problem to open.</p>
  
  <p>============= FINAL SOLUTION ============</p>
  
  <pre><code>private void Foo(object sender, EventArgs e)
  {
      SaveFileDialog saveFileDialog = new SaveFileDialog();
      saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
  
      saveFileDialog.FilterIndex = 0;
      saveFileDialog.RestoreDirectory = true;
      saveFileDialog.CreatePrompt = true;
      saveFileDialog.FileName = null;
      saveFileDialog.Title = "Save path of the file to be exported";
  
      if (saveFileDialog.ShowDialog() == DialogResult.OK)
      {
          Application excelObj = (Application)Marshal.GetActiveObject("Excel.Application");
          Activate(); // &lt;-- added (recommend by msdn, but maybe not nessary here)
          Workbook wbook = excelObj.ActiveWorkbook;
          wbook.SaveAs(saveFileDialog.FileName, XlFileFormat.xlExcel8, Type.Missing,
              Type.Missing, false, false, XlSaveAsAccessMode.xlNoChange, Type.Missing,
              Type.Missing, Type.Missing, Type.Missing, Type.Missing);
          //                wbook.Close(); // &lt;-- don't want this anymore
      }
  }
  </code></pre>