Excel Interop - Set filename before saving
.net, c#, com, excel, excel-interop
Solution
There is no explicit, foolproof way to do this prior to saving, unfortunately. The closest you could come is to use a template. If you have a template called `FOO.xltx`, you could create your workbook like this:
Application.Workbooks.Add "X:\path\to\FOO.xltx"
The only quirk is that the name for the new documents will be appended with an incrementing number (`FOO1` the first time, then `FOO2`,`FOO3`, etc.).
To create a template, just create a new document, and when you save it, select `Excel Template (*.xltx)` from the `Save as type` dropdown.
Problem
Is it possible to set the excel filename before file saving? I have following simple code: ``` using Excel = Microsoft.Office.Interop.Excel; Excel.Application excel = new Excel.Application(); excel.Visible = true; Excel.Workbook workbook = excel.Workbooks.Add(Excel.XlSheetType.xlWorksheet); Excel.Worksheet sheet = workbook.Sheets[1]; sheet.Cells[1, 1] = "Hello World!"; ``` Is it possible to predefine this name before saving? Thanks.