none
Showing built-in SaveAs dialog instead of MSOFileDialogSaveAs in PowerPoint RRS feed

  • Question

  • In Word and Excel there two ways to show the SaveAs dialog. The more general way which works for both Excel and Word:

    var dialog = Globals.ThisAddIn.Application.FileDialog[MsoFileDialogType.msoFileDialogSaveAs];
    dialog.InitialFileName = path;
    if (dialog.Show() == -1)
    {
      dialog.Execute();
    }

    Then there is also a product specific one. For Word this looks like:

    var dialog = Globals.ThisAddIn.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFileSaveAs];
    dialog.GetType().InvokeMember("Name", System.Reflection.BindingFlags.SetProperty, null, dialog, new object[] { path });
    if (dialog.Show() == -1)
    {
      dialog.Execute();
    }

    For Excel this looks very similar like this:

    var dialog = Globals.ThisAddIn.Application.Dialogs[Microsoft.Office.Interop.Excel.XlBuiltInDialog.xlDialogSaveAs];
    dialog.Show(path);

    The application specific APIs are the one which work like they should work. Let me clarify it. When I create a new document / workbook / presentation and I save (File -> Save As) it into a document library with multiple content types in SharePoint then each of the products asks me of which content type the document / workbook / presentation should be.

    The same behaviour is achieved by using the application specific API only. Showing the MSOFileDialogSaveAs doesn't ask which content type the file is.

    My problem is that in PowerPoint AddIn there is only the MSOFileDialogSaveAs dialog callable from the code. So the expected behavior is not achieved. How can I show the right dialog?

    Tuesday, January 21, 2014 11:55 AM

All replies

  • Hello Yavuz,

    Please try to use the following code to invoke the built-in command programmatically:

    Application.CommandBars.ExecuteMso("FileSaveAs");
    The ExecuteMso method of the CommandBars class executes the built-in control identified by the idMso parameter.
    Tuesday, January 21, 2014 1:24 PM
  • Thank you for your reply Eugene, but this does not help. As you can see in my examples the dialogs' initial file names are set from the outside without user interaction. If there is a way to send arguments to the built-it commands that would be helpful.
    Tuesday, January 21, 2014 1:47 PM
  • Hi Yavuz,

    Unfortunately the ExecuteMso method doesn't provide any optional arguments for specifying additional arguments for initializing the UI.

    PowerPoint doesn't provide such dialogs. Instead, I can suggest the following alternatives:

    1. Run an instance of the Word application in the background and show the required dialog. You can read more about this in the How to: Programmatically Use Built-In Dialog Boxes in Word article in MSDN.
    2. Use the SaveFileDialog class which comes from the .NET BCL(see Microsoft.Win32.FileDialog for details)
    3. Create your own custom dialog based on the System.Windows.Forms.Form class.

    It is up to you which way is to choose.

     


    • Edited by Eugene Astafiev Friday, January 24, 2014 4:37 PM syntax correction
    Thursday, January 23, 2014 6:16 PM
  • Hi Eugene,

    Thank You for your suggestions. The problem is not do build a new dialog. It is calling an existent dialog.

    I create a new presentation. Then I go to the menu File -> Save As. I specify a SharePoint document library as the location, give it a name and press the OK button. Because the document library has content types attached PowerPoint asks me to choose one of them for the new presentation.

    The code (the only available API in PowerPoint?)

    var dialog = Globals.ThisAddIn.Application.FileDialog[MsoFileDialogType.msoFileDialogSaveAs];
    dialog.InitialFileName = path;
    if (dialog.Show() == -1)
    {
      dialog.Execute();
    }

    does not ask me. It associates the presentation with the first content type.

    I really do not want to reverse engineer. I want to use the feature but it seems to be that there is no API for that.

    Monday, January 27, 2014 12:02 PM
  • The PowerPoint object model doesn't provide any application specific dialogs.
    Tuesday, January 28, 2014 6:31 PM