0

Having an issue figuring out how to prompt to choose the files I want to email.

Dim olApp As Outlook.Application
Dim diaFolder As FileDialog
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
Set olApp = CreateObject("Outlook.Application")
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = "[email protected]"
olMail.Subject = "Subject Line"
olMail.Body = "Body of the Email"

diaFolder.AllowMultiSelect = True
diaFolder.Show

MsgBox diaFolder.SelectedItems

Set diaFolder = Nothing

olMail.Send
2
  • 1
    This should help
    – BruceWayne
    Nov 20, 2018 at 18:14
  • Do you want the user to pick a folder, or one or more individual files? If files then Application.GetOpenFilename is what you need to look at. Nov 20, 2018 at 18:15

1 Answer 1

2

You can try this out:

Sub sendAttachment()

    Dim olApp As Outlook.Application
    Dim diaFolder As FileDialog
    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    Set olApp = CreateObject("Outlook.Application")
    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)
    Dim lngCount As Long

    olMail.To = "[email protected]"
    olMail.Subject = "Subject Line"
    olMail.Body = "Body of the Email"


    ' Open the file dialog
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = True
        .Show

        ' Display paths of each file selected
        For lngCount = 1 To .SelectedItems.Count
            attFilePath = Application.FileDialog(msoFileDialogOpen).SelectedItems(lngCount)
            olMail.Attachments.Add (attFilePath)
        Next lngCount

    End With

    olMail.Display
    'olMail.Send

End Sub

I hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.