<p>The problem: Loading an excel spreadsheet template.  Using the Save command with a different filename and then quitting the interop object.  This ends up saving the original template file. Not the result that is liked.</p>

<pre><code>public void saveAndExit(string filename)
{        
    excelApplication.Save(filename);
    excelApplication.Quit();
}
</code></pre>

<p>Original file opened is c:\testing\template.xls
The file name that is passed in is c:\testing\7777 (date).xls</p>

<p>Does anyone have an answer?</p>

<p>(The answer I chose was the most correct and thorough though the wbk.Close() requires parameters passed to it.  Thanks.)</p>

[{'answer_id': 29218, 'author': 'Joel Lucsy', 'author_id': 645, 'author_profile': 'https://Stackoverflow.com/users/645', 'pm_score': 0, 'selected': False, 'text': '<p>Have you tried the SaveAs from the Worksheet?</p>\n'}, {'answer_id': 29222, 'author': 'Jason Z', 'author_id': 2470, 'author_profile': 'https://Stackoverflow.com/users/2470', 'pm_score': 1, 'selected': False, 'text': '<p>Rather than using an ExcelApplication, you can use the Workbook object and call the SaveAs() method.  You can pass the updated file name in there.</p>\n'}, {'answer_id': 29232, 'author': 'Kevin Crumley', 'author_id': 1818, 'author_profile': 'https://Stackoverflow.com/users/1818', 'pm_score': 4, 'selected': True, 'text': "<p>Excel interop is pretty painful.  I dug up an old project I had, did a little fiddling, and I think this is what you're looking for.  The other commenters are right, but, at least in my experience, there's a lot more to calling SaveAs() than you'd expect if you've used the same objects (without the interop wrapper) in VBA.</p>\n\n<pre><code>Microsoft.Office.Interop.Excel.Workbook wbk = excelApplication.Workbooks[0];  //or some other way of obtaining this workbook reference, as Jason Z mentioned\nwbk.SaveAs(filename, Type.Missing, Type.Missing, Type.Missing,\n            Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, \n            Type.Missing, Type.Missing, Type.Missing, Type.Missing,\n            Type.Missing);\nwbk.Close();\nexcelApplication.Quit();\n</code></pre>\n\n<p>Gotta love all those Type.Missings.  But I think they're necessary.</p>\n"}, {'answer_id': 30341, 'author': 'Rad', 'author_id': 1349, 'author_profile': 'https://Stackoverflow.com/users/1349', 'pm_score': 0, 'selected': False, 'text': '<ol>\n<li>Ditto on the SaveAs</li>\n<li>Whenever I have to do Interop I create a separate VB.NET class library and write the logic in VB. It is just not worth the hassle doing it in C#</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/29141', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3135/']