Sunday, 6 November 2016

Excel macro to send e-mail with attachments using outlook

  Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
lr = Range("A65536").End(xlUp).Row 'Detects the last row with data
If lr > 1 Then
    Set OutApp = CreateObject("Outlook.Application")
    For i = 2 To lr
    Set OutMail = OutApp.CreateItem(0)

    strbody = "Enter your mail content here"

    With OutMail
        .To = "Enter email address of the receiver"
        .CC = ""
        .BCC = ""
        .Subject = "Enter subject line here"
        .Body = strbody
        'You can add a file like this
        '.Attachments.Add ("C:\test.txt")
        .Send
    End With


    Set OutMail = Nothing
    Next
    Set OutApp = Nothing
End If

No comments:

Post a Comment