0

I am trying to open a SAVE AS FileDialog in OUTLOOK (MS Office 2013 or 2016). Since Outlook does not support FileDialogs, I use Excel (this seems to be the preferred approach based on dozens of searches).

I have had success opening a FilePicker dialog (msoFileDialogFilePicker) and File Open, but I just cannot get this to work for a SaveAs dialog (msoFileDialogSaveAs).

Could anyone please explain why the SaveAs does not work, but the FilePicker does. Or, could someone explain what I am doing wrong.

Here is some sample code. Each of These DOES Work:

Dim xlobj As Excel.Application
Set xlobj = New Excel.Application

Dim objDialog As FileDialog
Set objDialog = xlobj.FileDialog(msoFileDialogOpen)  'This WORKS
Set objDialog = xlobj.FileDialog(msoFileDialogFolderPicker)  ' This Works too
Set objDialog = xlobj.FileDialog(msoFileDialogFilePicker) ' This also works

objDialog.Show

HOWEVER, when I try to use msoFileDialogSaveAs I get an Error (Error -Automation Error The remote procedure call failed).

Dim xlobj As Excel.Application
 Set xlobj = New Excel.Application

 Dim objDialog As FileDialog
 Set objDialog = xlobj.FileDialog(msoFileDialogSaveAs) ' This throws ERROR???

I would welcome any ideas or onsights.

Thanks very much,

DGP

PS. In case its relevant. The user needs to save some of their email messages in a Legal Folder. I have built a way to Save them directly using the Sender or Recipient and a date stamp as the file name. For this use case, they want a File Dialog so that they can manually name the File they are about to save.

DGP
  • 167
  • 1
  • 14
  • SaveAs what? What are you saving?There is no workbook just the app instance. Add/Open a workbook for the application and then attempt to invoke SaveAs dialog. – cyboashu Jul 09 '18 at 16:43
  • We are trying to save the Outlook Message. I only use Excel because Outlook does not support FileDialog use. – DGP Jul 09 '18 at 17:54
  • To use SaveAs, you need to have a worbook open. On bare application object it will throw error. simple. – cyboashu Jul 09 '18 at 18:01
  • OK. I guess that makes some sense. Then, does anyone know how to open a SaveAs File Dialog from Outlook? – DGP Jul 09 '18 at 18:59

1 Answers1

0

Outlook VBA can simulate a button press with ExecuteMso.

Private Sub ExecuteMso_FileSAveAs()

    Dim currItem As Object

    Set currItem = ActiveInspector.currentItem

    ' Hover over the icon that you would add as a button
    ' The IdMso to use in ExecuteMso is the last part of the text displayed.
    ActiveInspector.CommandBars.ExecuteMso ("FileSaveAs")

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52
  • This is very interesting. I will see if I can exploit this. Thanks! – DGP Jul 12 '18 at 21:07
  • Niton.Thanks again for this information. Is it possible to set the FileFolder to a specific directory when it opens? Part of my challenge is that the Users want to be brought right to a folder which is the specific storage location for a particular legal matter. – DGP Jul 17 '18 at 20:42
  • As indicated in [CommandBars.ExecuteMso Method](https://msdn.microsoft.com/en-us/vba/office-shared-vba/articles/commandbars-executemso-method-office) the method is for button pressing. – niton Jul 17 '18 at 21:17
  • You could suggest a shortcut to the folder on the desktop, where the user could drag a copy of the mail. – niton Jul 17 '18 at 21:20