Skip to main content

Kutools for Office β€” One Suite. Five Tools. Get More Done.

How To Quickly Open The File Dialog Box To Insert An Attachment In Outlook?

Author Siluvia Last modified

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.

steps of opening the file dialog box to insert an attachment in outlook

3. Click Insert > Module. Then copy one of the following VBA codes to the Module window.

steps of opening the file dialog box to insert an attachment in outlook

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:

1) The VBA code 1 helps to open the default Documents folder in your computer.
2) In the VBA code 2, please change the folder path in the following line to the folder path you need.
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.

steps of opening the file dialog box to insert an attachment in outlook

6. In the Outlook Options dialog box, you need to configure as follows.

6.1) In the Choose commands from drop-down list, select Macros;
6.2) Select the macro you added in the previous step;
6.3) Click the Add button to add this macro to the Customize Quick Access Toolbar box.
steps of opening the file dialog box to insert an attachment in outlook

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.

steps of opening the file dialog box to insert an attachment in outlook

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.

steps of opening the file dialog box to insert an attachment in outlook

Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook with 100+ incredible features! Click to download now!

πŸ€– Kutools AI : Uses advanced AI technology to handle emails effortlessly, including replying, summarizing, optimizing, extending, translating, and composing emails.

πŸ“§ Email Automation: Auto Reply (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

πŸ“¨ Email Management: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

πŸ“ Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

πŸ‘ One-click Wonders: Reply All with Attachments  /   Anti-Phishing Emails  /  πŸ•˜Show Sender's Time Zone ...

πŸ‘©πŸΌβ€πŸ€β€πŸ‘©πŸ» Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Instantly unlock Kutools for Outlook with a single click. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2

πŸš€ One-Click Download β€” Get All Office Add-ins

Strongly Recommended: Kutools for Office (5-in-1)

One click to download five installers at once β€” Kutools for Excel, Outlook, Word, PowerPoint and Office Tab Pro. Click to download now!

  • βœ… One-click convenience: Download all five setup packages in a single action.
  • πŸš€ Ready for any Office task: Install the add-ins you need, when you need them.
  • 🧰 Included: Kutools for Excel / Kutools for Outlook / Kutools for Word / Office Tab Pro / Kutools for PowerPoint