How To Quickly Open The File Dialog Box To Insert An Attachment In Outlook?
When we need to insert an attachment in a composing email, usually we need to click Insert > Attach File > Browse This PC to open the Insert File dialog box, then find and insert the file we need. In this tutorial, we provide two VBA codes to help you open the Insert File dialog box easily with just one click.
Quickly Open The File Dialog Box To Insert An Attachment With VBA
The following VBA codes can achieve:
VBA code 1: Open the default Documents folder in your computer
VBA code 2: Open the specified folder in your computer
Please do as follows to get it done.
1. Launch your Outlook, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Tools > References, then check the Microsoft Scripting Runtime box in the References – Project1 dialog box.
3. Click Insert > Module. Then copy one of the following VBA codes to the Module window.
VBA code 1: Open the default Documents folder in your computer
Sub OpenFileDialog()
'Updated by Extendoffice 20220713
Dim xApp As Object
Dim xFileDlg As FileDialog
Dim xSelItem As Variant
Dim xMail As MailItem
On Error Resume Next
Set xApp = CreateObject("Excel.Application")
xApp.Visible = False
Set xFileDlg = xApp.Application.FileDialog(msoFileDialogFilePicker)
xFileDlg.AllowMultiSelect = True
If xFileDlg.Show = 0 Then Exit Sub
Set xMail = Application.ActiveInspector.currentItem
For Each xSelItem In xFileDlg.SelectedItems
xMail.Attachments.Add xSelItem
Next
xApp.Quit
Set xFileDlg = Nothing
Set xApp = Nothing
End Sub
VBA code 2: Open the specified folder in your computer
Sub OpenCertianFolderDialog()
'Updated by Extendoffice 20220713
Dim xApp As Object
Dim xFileDlg As FileDialog
Dim xSelItem As Variant
Dim xMail As MailItem
On Error Resume Next
Set xApp = CreateObject("Excel.Application")
xApp.Visible = False
Set xFileDlg = xApp.Application.FileDialog(msoFileDialogFilePicker)
xFileDlg.InitialFileName = "C:\Users\Win10x64Test\Desktop\save attachments\" 'Specify the path to the folder you want to open
xFileDlg.AllowMultiSelect = True
If xFileDlg.Show = 0 Then GoTo L1
Set xMail = Application.ActiveInspector.CurrentItem
For Each xSelItem In xFileDlg.SelectedItems
xMail.Attachments.Add xSelItem
Next
L1:
xApp.Quit
Set xFileDlg = Nothing
Set xApp = Nothing
End Sub
Notes:
xFileDlg.InitialFileName = "C:\Users\Win10x64Test\Desktop\save attachments\"
Then the specified folder will be opened each time you run this code.
4. Press the Alt + Q keys to close the Microsoft Visual Basic for Applications window.
Now you need a button to run the macro.
5. Click Home > New Email to create a new email. In the message window, click Customize Quick Access Toolbar > More Commands.
6. In the Outlook Options dialog box, you need to configure as follows.
7. Keep the script selected in the right box, and then click the Modify button. In the Modify Button dialog box, assign a new button to the script and click OK.
8. Click OK in the Outlook Options dialog box to save the changes.
9. The button you specified in step 7 is then added to the Quick Access Toolbar. When composing an email, if you want to insert an attachment, you can just click on this button to open the Browse folder and select the file you need to insert.
Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!
- Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
- BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
- Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
- Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
- Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.

