none
How to set default save format and initial file name for wdDialogFileSaveAs? RRS feed

  • Question

  • I have the following code:

    Word.Dialog wordSADialog = _wordApp.Dialogs[Word.WdWordDialog.wdDialogFileSaveAs];

    wordSADialog.Show();

    How do I set initial file name and default save format for this dialog?


    • Edited by Davit93 Thursday, January 25, 2018 2:33 PM
    Thursday, January 25, 2018 2:33 PM

All replies

  • Hello Davit93,

    I would suggest you use FileDialog object instead of Dialog object.

    Here is the example.

                FileDialog fileDialog = _wordApp.FileDialog[MsoFileDialogType.msoFileDialogSaveAs];
                string fileName = "Pre-Set FileName";
                string formatSuffix = "*.docm";
                for (int i = 1; i <= fileDialog.Filters.Count; i++) {
                    if (fileDialog.Filters.Item(i).Extensions== formatSuffix) {
                        fileDialog.FilterIndex = i;
                        break;
                    }
                }
                fileDialog.InitialFileName = fileName;
                if (fileDialog.Show()!= 0) {
                    fileDialog.Execute();
                }

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 26, 2018 6:28 AM
  • Hi Terry, Thanks for your reply. Actually I was using FileDialog object previously, but tools are missing in that dialog. See the attached photos. Therefore I switched to Dialog object, where they are present. However, for Dialog object I am not able to set initial file name and default set format.

    FileDialog object tools:

    Dialog object tools

    Do you know either how to enable tools for FileDialog or set initial filename and default save format for Dialog object.

    Friday, January 26, 2018 7:50 AM
  • Hello Davit93,

    Dialogs collection will return different dialog according to dialog type. Different dialogs have different members.

    A wdDialogFileSaveAs does have Name/Format property, however we have to use it through late-binding feature.

    Here is the code example.

     dynamic wordSADialog = _wordApp.Dialogs[Word.WdWordDialog.wdDialogFileSaveAs];
                wordSADialog.Name = "Test";
                wordSADialog.Format = Word.WdSaveFormat.wdFormatXMLDocumentMacroEnabled;
                wordSADialog.Show();

    For late-binding feature, please refer to below link for more information.

    Late Binding in Office Solutions

    For members you could use for different dialog, please refer to below link.

    WdWordDialog enumeration

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, January 26, 2018 9:35 AM