VBA Send Email With Attachments From a Folder in Excel

VBA & macros · Updated November 18, 2026

To send an Outlook email with every file in a folder attached, run an Excel VBA macro that loops through the folder’s files, adds each path to an Outlook message, and displays the message for review. The example below is for Excel on Windows with classic Outlook installed; check the recipient and attachments before changing .Display to .Send.

How the folder-to-email macro works

Excel VBA can automate the classic Outlook desktop application through Outlook’s object model. The macro creates an Outlook message, reads the files in a specified folder, adds them as attachments, and opens the completed draft. It does not send one email per file: it creates one message with all files in the folder attached.

The example uses a folder path written into the macro, such as C:\Reports\ReadyToSend. It checks that the folder exists and contains files before creating the message. It loops through files in that folder itself, not files inside its subfolders. If your folder has nested folders, those contents will not be attached unless you add recursive folder-processing code.

This approach is useful for a regular report pack, invoice batch, or collection of documents that belongs in one email. It is less suitable if the folder contains unrelated, confidential, or very large files: inspect the contents first, or use a process that selects files individually.

Prepare Excel and Outlook on Windows

  1. Open the workbook in Excel for Microsoft 365 on Windows and save a working copy as an Excel Macro-Enabled Workbook (.xlsm). A macro cannot be undone with Ctrl+Z, so keep a backup before running it.
  2. Open the Visual Basic Editor with Alt+F11, or use Developer > Visual Basic. If the Developer tab is not visible, enable it through File > Options > Customize Ribbon and select Developer.
  3. In the editor, choose Insert > Module and paste the code below into the new standard module.
  4. Change the folder path, recipient, subject, and message text to suit your task. Make sure the folder path points to a real folder and the recipient address is correct.
  5. Return to Excel and run the macro with Alt+F8, select EmailFolderFiles, then choose Run. Review the draft Outlook opens before sending it.

The macro uses late binding: it declares Outlook objects as generic objects and does not require you to add an Outlook reference in the VBA editor. Outlook must still be installed as a supported desktop application, and a mail profile must be available. This is not a macro for Excel for the web, which does not run VBA.

VBA code to attach the files

Replace the sample values in the first few lines. The code deliberately uses .Display, which opens the message for review rather than sending it immediately.

Option Explicit

Sub EmailFolderFiles()
    Dim fso As Object
    Dim folder As Object
    Dim file As Object
    Dim olApp As Object
    Dim olMail As Object
    Dim folderPath As String
    Dim recipient As String

    ' Set these values for your email and source folder.
    folderPath = "C:\Reports\ReadyToSend"
    recipient = "recipient@example.com"

    Set fso = CreateObject("Scripting.FileSystemObject")

    If Not fso.FolderExists(folderPath) Then
        MsgBox "Folder not found: " & folderPath, vbExclamation
        Exit Sub
    End If

    Set folder = fso.GetFolder(folderPath)
    If folder.Files.Count = 0 Then
        MsgBox "The folder contains no files to attach.", vbInformation
        Exit Sub
    End If

    ' Connect to Outlook, or start it if it is not already open.
    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")
    If olApp Is Nothing Then
        Set olApp = CreateObject("Outlook.Application")
    End If
    On Error GoTo 0

    If olApp Is Nothing Then
        MsgBox "Outlook could not be opened.", vbExclamation
        Exit Sub
    End If

    Set olMail = olApp.CreateItem(0)

    With olMail
        .To = recipient
        .Subject = "Files from the reports folder"
        .Body = "Hello," & vbCrLf & vbCrLf & _
                "Please find the files attached." & vbCrLf

        For Each file In folder.Files
            .Attachments.Add file.Path
        Next file

        .Display
    End With
End Sub

Before the first run, save a copy of the workbook: macros cannot be reversed with Ctrl+Z. The code checks for a missing or empty folder and for Outlook being unavailable. It does not validate the email address, check the contents of the files, or guarantee that Outlook will deliver the message.

Choose the right folder and email details

Use a complete folder path, including the drive letter for a local folder or the appropriate network path for a shared location. For example, a network share might use a path such as \\fileserver\team\reports. The Windows account running Excel needs permission to read the folder and its files. If the path is on a network, confirm the connection is available when you run the macro.

The sample creates a plain-text email. Edit .To, .Subject, and .Body to set its recipient, subject, and message. Separate multiple recipients with semicolons, as in person1@example.com; person2@example.com. For a carbon-copy recipient, set .CC; for a blind carbon-copy recipient, set .BCC. Confirm your organization’s rules before including addresses in those fields.

To use a formatted HTML message instead of plain text, set the message’s .HTMLBody property with valid HTML rather than relying on .Body for formatting. Keep the body content appropriate for email, and test the draft in Outlook because its appearance can vary with email clients and settings.

Review the message or send it automatically

.Display is the safer default for a new macro. It lets you see the To, CC, subject, body, and attachments before sending. Once the process is reliable and you have safeguards in place, replacing .Display with .Send tells Outlook to submit the message using its configured account. Sending does not prove that the recipient received or read it; delivery can still fail or be delayed.

For a recurring automated task, consider adding checks before the send action. For example, confirm that the expected number of files is present, that each filename follows a known pattern, and that the recipient is not blank. You can also display a confirmation prompt before sending. These checks matter because .Send can send the wrong files or address if the folder or settings have changed.

If the goal is one email per file rather than one email containing all files, the code needs a different structure: create a new message inside the file loop and attach only the current file. Do not simply move .Display or .Send without checking the loop’s behavior. A mistake can produce many duplicate or unintended messages.

Common problems and practical fixes

  • “Folder not found” appears: Check spelling, drive letter, and network availability. Avoid a trailing typo in the path, and confirm that the folder is accessible in File Explorer under the same Windows account.
  • Outlook could not be opened: Confirm classic Outlook is installed and has been set up with a mail profile. On managed work computers, automation may be restricted by administrator settings or security software.
  • The draft has no attachments: Check that the selected folder contains files directly, not only subfolders. Confirm Excel can access the files and that they are not being moved or deleted while the macro runs.
  • The email will not send: Review Outlook’s Outbox and connection status, verify the chosen account and recipient, and check whether your organization limits automated messages or attachment sizes. Outlook may open a security warning or be governed by policy settings.
  • The attachment is rejected: A mail server or recipient system may limit message size or block particular file types. Compressing files is not always permitted or helpful; use an approved shared link or transfer service when the files are too large.

For easier diagnosis, test with a temporary folder containing one harmless file and send the draft to yourself only after reviewing it. If you add more code, handle errors explicitly and report which file failed. Do not assume a macro completed successfully just because Excel returned to the worksheet.

Safety, privacy, and attachment limits

A folder-wide attachment macro can include files that were not meant for the recipient. Before sending, check the filenames and open the draft’s attachment list. Keep sensitive information out of a general-purpose folder, and use the organization’s approved method for confidential or regulated material. The macro does not encrypt attachments or apply access permissions to them.

Message size limits vary by mail service and recipient organization. Attachments also become larger when encoded for email, so a set of files close to a provider’s stated limit may still fail. If the files are large, a managed cloud-sharing link may be a better choice, provided the sharing permissions are set for the intended recipients.

Only run macros from workbooks you trust. Do not weaken Excel’s macro security settings simply to make an unfamiliar workbook run. Organizations may manage macro policies centrally, and Outlook may apply its own programmatic-access controls. If automation is blocked, ask your IT administrator about the approved method rather than trying to bypass those controls.

Windows, Mac, and other options

This Outlook automation example is for Windows and classic Outlook, which exposes the COM automation interface used by the macro. Microsoft’s New Outlook for Windows does not provide the same COM/VBA automation support, so this code may not work with it. Excel for the web cannot run VBA either.

Excel for Mac has a Visual Basic Editor, commonly opened from Tools > Macro > Visual Basic Editor; the keyboard shortcut may be Option+F11 or Fn+Option+F11, depending on the keyboard. However, Mac Excel cannot use this Windows COM-based Outlook code as written. For a cross-platform or cloud workflow, consider an approved Power Automate flow, an Outlook-supported automation approach for your environment, or a manual attachment process. Choose based on your organization’s account, licensing, and security policies.

Frequently Asked Questions

Can VBA attach every file in a folder to one email?
Yes. The example loops through the folder’s files and adds each one to a single Outlook message. It does not include files stored only in subfolders.

Can I send each file as a separate email?
Yes, but the macro must create a separate Outlook message for each file. That is different from attaching all files to one message, and it should be tested carefully to avoid sending duplicates.

Will this work with New Outlook?
Not reliably as written. The code uses Outlook COM automation for classic Outlook on Windows, which New Outlook does not support in the same way. Use an approved alternative for your Outlook setup.

How do I attach files from a subfolder too?
The sample checks only the selected folder’s direct files. To include nested folders, add code that recursively visits each subfolder and attaches its files, or organize the intended attachments in one folder first.

How do I send the email without reviewing it?
After verifying the macro and its safeguards, replace .Display with .Send. Test with a safe recipient first; the macro will submit the message through Outlook’s configured account rather than asking you to review the draft.

Can I run this macro from Excel for the web or Mac?
No, not as written. Excel for the web does not run VBA, and the Outlook COM automation in this example is Windows-specific. Use a supported automation option for those platforms.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.