jwp3

Hi, I can't resolve problem how to save spreadsheet in any format: xls or xlsx.
I use office2007, but some of people in my office still use excel2003. They must decide
in which format save excel.

I wrote:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
... and ...
xlApp.Dialogs(Excel.XlBuiltInDialog.xlDialogSaveAs).Show("xxx")

all is ok, default name is "xxx", but I'd like set default extension and I wrote:

xlApp.Dialogs(Excel.XlBuiltInDialog.xlDialogSaveAs).Show("xxx", Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel9795)

and here is problem, I got error.

How can I set default name, extension and location where I want save my file
And a second question: how I can check which button was pressed in DialogBox
In a SaveFileDialog I wrote:
"If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then"
but how check it in a xlApp.Dialogs

Source is VB.net2005.
Regards, Jacek



Re: Visual Studio Tools for Office Excel.XlBuiltInDialog.xlDialogSaveAs

Ji Zhou – MSFT

Hi Jacek,

We can use the Application.get_FileDialog to get the SaveAsDialog’s handle. Then it is easy to achieve what you want. Codes:

Code Block

Office.FileDialog fd = app.get_FileDialog(MsoFileDialogType.msoFileDialogSaveAs);

fd.InitialFileName = "test"; //This line set the default file name

fd.FilterIndex = 4; //This line set the extension

//If we click cancel, the dialog will return 0.Click OK will return a none zero value

if (fd.Show() != 0)

{

fd.Execute();

}

Thanks

Ji