0

I have the following code that saves the file in the default Excel version ona given user's machine.

xlWorkBook.SaveAs("c:\\AMORT_data", Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

How can I use the SaveFiledialog (particularly .filter) format use this syntax? I tried something like this but I get the old "Cannot complicitly convert...." error. Is it simply a matter of converting the Excel Default to a string or is it more complicated.

saveFileDialog1.Filter = Excel.XlFileFormat.xlWorkbookDefault;
Ryan Ward
  • 1,523
  • 4
  • 15
  • 23

1 Answers1

0

Have you tried the following below:

saveFileDialog1.Filter = "Excel file|*.xls";

This should limit files to be shown in the saveFileDialog as an .xls file. The whole example of opening and saving files from a saveFileDialog can be seen here.

Take note that the SaveFileDialog is not responsible for saving the file per se. It just shows you where you will be saving your file. To make sure that the file you are saving is an excel file you can just check the file extension prior to saving so that you can inform the user of the correct format to use.

lem.mallari
  • 1,274
  • 12
  • 25
  • It doesn't limit you to saving files with that extension. It just limits the existing files that show up in the list. But you're right, you do need to format the string you specify for `Filter` this way. – Cody Gray - on strike Apr 23 '13 at 04:24
  • Updated my answer to clarify what Filter option does. – lem.mallari Apr 23 '13 at 04:33
  • Yeah I was thinking I could limit it manually by keying in .xls and .xlsx file types, but then I never know when Microsoft will create yet another type. I was trying to force it through the default option since that was working in my prior code where I was saving it to a pre-determined location. – Ryan Ward Apr 23 '13 at 13:16