How To Use Excel.Application.GetSaveAsFilename() Method


Have you ever wanted to use the Excel.Application.GetSaveAsFilename method to save your files?


Excel.Application excel = new Excel.Application();

FileInfo fileInfo = new FileInfo(txtInputFile.Text.Trim());

//so show the save as, and then filter by current extension only....reason is, that SaveAs() will save in current format, so format changes cannot happen here.
object fileName = excel.GetSaveAsFilename(fileInfo.Name, string.Format("Excel files (*{0}), *{0}", fileInfo.Extension), 1, "Save File Location");



This example will display the Save As dialog box.  I limit the box to the current file type, as calling excel.SaveAs(filename) will not change the file type.