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
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.
- From your Outlook VBA Editor, go to Tools > References
- 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
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.
This macro opens the
- msoFileDialogOpen - Display an Open Dialog Box
- msoFileDialogSaveAs - Display a Save As Dialog Box
- msoFileDialogFilePicker - Display a File Picker Dialog Box
- msoFileDialogFolderPicker - Display a Folder Picker Dialog Box
Here’s what the Folder Picker looks like from Outlook:
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:)
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!