Rishab

I have a VSTO 2005 SE add-in for excel in which I need to programatically save the document on an event. When I tried workbook.save() to accomplish this the workbook gets saved with its temporary name eg "Book1.xlsx" in My Documents and doesnt pop-up a save as dialogue even with a document which is previously unsaved. I tried this with a word document and there the behaviour was as expected ie. it shows a save-as dialogue for a fresh document and doesn't when the document has been previously saved. Is there a workaround to avoid this behaviour

As a crude workaround I wrote the following code.

string path = workbook.Path;

if (String.IsNullOrEmpty(path))

{

SaveFileDialog dialog = new SaveFileDialog();

dialog.DefaultExt = ".xlsx";

if (dialog.ShowDialog() == DialogResult.OK)

{

workbook.SaveAs(dialog.FileName, workbook.FileFormat, missing, missing, false, false, Excel.XlSaveAsAccessMode.xlNoChange, missing,missing, missing, missing, missing);

}

}

else

workbook.Save();

While this gets the work done, I'd like to add support to save in any of the file-formats supported by excel 2007 and not just .xlsx. Is there any way to achieve this

Thanks

Rishab



Re: Visual Studio Tools for Office Workbook.save() not behaving as expected.

Cindy Meister

The Excel (and Word) object models let you display many of their built-in dialog boxes so that you don't have to recreate the functionality. here's the VB code to display Excel's SaveAs dialog box:

Application.Dialogs(xlDialogSaveAs).Show

To use it in your Addin, you just need to subsitute the object that represents the Excel application for Application, then fully qualify xlDialogSaveAs. Intellisense will probably show you that as soon as you type Dialogs(






Re: Visual Studio Tools for Office Workbook.save() not behaving as expected.

Rishab

Thanks for the response Cindy.

Is there a way to do the same in C# i cant seem to find the equivalent classes.

Thanks

Rishab.





Re: Visual Studio Tools for Office Workbook.save() not behaving as expected.

Geoff Darst - MSFT

Hi,

The C# code would look something like this.

Application.Dialogs[Excel.XlBuiltInDialog.xlDialogSaveAs].Show(missing, missing, missing, missing,missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing,missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

Sincerely,

Geoff Darst

Microsoft VSTO Team