Sending Mail using Excel VBA

Last three days, including weekend, were quite hectic for me. I spend 2/3rd of my time in railway, roadway, airway and remaining 1/3rd setting my house and looking after my sister. She met with a fatal accident. Pray for her speedy recovery.

I am back again. I was developing a Project Dashboard. I thought to add a feature to it. There were several people actively working in sync with one another. A delay or a slip in deadline might prove catastrophic for entire team. Hence, to track progress, I added a feature to track the status of their work. I will talk about this feature in my later blog. Developers have to update their status on daily basis. If somebody forgot to update it, I would ask them to update it ASAP. This was quite a manual process, first find who has not updated the status and then send a reminder by drafting a mail. Can I automate it to some extent? Yes, I can. I automated the mail part of the same.

I added a Command Button "Send Reminder Mail" in Dashboard sheet. Beside this I added a TextBox (Textbox1). The body of the mail (to be send) can be updated into this TextBox. Following code snippet was added to send MAIL to the concerned developer.

Sub CommandButton1_Click()
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
   ' This section configures the Mail Address, Subject, Body of the Mail etc
    With OutMail

        'Update the Mail Address
        .To = "XYX@xyz.com"
       
        'Update CC
        .CC = ""
       
        'Update BCC
        .BCC = ""
       
        'Update Subject of the Mail
        .Subject = "Gentle Reminder"
       
        'Update body of the Mail
        If (TextBox1.Text = "") Then
            .Body = "Gentle Reminder .. Update Status"
        Else
            .Body = TextBox1.Text
        End If
       
        'Add Attachements if any
        '.Attachments.Add ActiveWorkbook.Sheet1
       
        'Incase you need more files
        '.Attachments.Add ("C:\test.txt")
        'Send mail
        .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub


Just make one sure, your Outlook is configured to send and receive mail.

Happy VBA...ing