The Application.FileDialog family of dialog boxes works fine for most Microsoft Office products, but will fail with run-time error 438 when issuing the command from Microsoft Outlook VBA. In other words, there is no FileDialog property under the Application object in Outlook VBA.

Outlook Runtime Error 438 Application FileDialog
Outlook Runtime Error 438 Application FileDialog

In this tutorial, I’m going to show you how to still use the same dialog prompts in Outlook without receiving this error.


Tutorial - Outlook FileDialog

To use the FileDialog suite of dialog boxes from Outlook, you’ll have to create a reference to the Microsoft Excel or Microsoft Word object library. I’ll use the Excel Object Library in this example.

  1. From your Outlook VBA Editor, go to Tools > References
  2. Scroll down and check the box beside Microsoft Excel XX.0 Object Library, where XX is an integer, like 14.

Add Reference to Excel Object Library
Add Reference to Excel Object Library

Once this is done, copy and paste the following macro in your Outlook Module.

Sub SelectFolder()
Dim sFolder As String
Dim xlObj As Excel.Application
    Set xlObj = New Excel.Application
    ' Open the select folder prompt
    With xlObj.FileDialog(msoFileDialogFolderPicker)
        If .Show = -1 Then ' if OK is pressed
            sFolder = .SelectedItems(1)
        End If
    End With
    xlObj.Quit
    Set xlObj = Nothing
    If sFolder <> "" Then ' if a file was chosen
        ' *********************
        ' put your code in here
        ' *********************
    End If
End Sub

Write better macros in half the time
Join thousands of others improving their VBA knowledge for free with our email series. Subscribe for more of our best VBA tips and access to our entire macro library.

I want to join the free VBA email series

This macro opens the msoFileDialogFolderPicker, but you can change it to any of the other MsoFileDialogTypes. For a refresher, The following FileDialog types can be entered in the parentheses beside xlObj.FileDialog:

  1. msoFileDialogOpen - Display an Open Dialog Box
  2. msoFileDialogSaveAs - Display a Save As Dialog Box
  3. msoFileDialogFilePicker - Display a File Picker Dialog Box
  4. msoFileDialogFolderPicker - Display a Folder Picker Dialog Box

Here’s what the Folder Picker looks like from Outlook:

VBA msoFileDialogFolderPicker FileDialog
VBA msoFileDialogFolderPicker Prompt

Notice the little Excel logo in the upper left of the FileDialog prompt. That’s there because we’re calling the Excel version of the FialDialog:)

Comments

If you haven’t already done so, please subscribe to my email list!

Leave a comment below so we can each learn from each other.
Oh, and please share this article on social media and follow me on Twitter for even more great VBA content!