Today We will learn how to send email from excel automatically.
First of all You need to create a table in excel. In my case I have created a table where
1st Column is Recipient Name
2nd Column has email address
and 3rd column has massage
4th, 5th, & 6th column is for attachment where we put only file path which file you want to insert in your mail. If you would not want to sent attachment then keep this cells blank. And the last Column is Status. If you send mail then status will change to "EMAIL has been sent". Email will be sent only when if the status is blank or not equal to "EMAIL has been sent"
The VBA codes which I used.....
Option Explicit
Sub sendmail()
Dim outlookApp As Object
Dim Email As Object
Dim Subj As String
Dim mailAddress As String
Dim Msg As String
Dim cell As Range
Dim Recipient As String
Dim Attchm1, Attchm2, Attchm3 As String
' create outlook object
Set outlookApp = CreateObject("Outlook.Application")
Subj = "Learn about Excel VBA"
'loop
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "*@*" And cell.Offset(0, 5).Value <> "EMAIL has been Sent" Then
mailAddress = cell.Value
Recipient = cell.Offset(0, -1).Value
'compose massage
Msg = "Dear" & Recipient & vbNewLine & cell.Offset(0, 1)
Attchm1 = cell.Offset(0, 2).Value
Attchm2 = cell.Offset(0, 3).Value
Attchm3 = cell.Offset(0, 4).Value
'create mail and send it
Set Email = outlookApp.createitem(0)
With Email
.to = mailAddress
.Subject = Subj
.body = Msg & vbNewLine & "Thanks & regards" & vbNewLine & "Nimai Sutradhar" _
& vbNewLine & Date & " " & Time
If Attchm1 <> "" Then
.attachments.Add Attchm1
Else
End If
If Attchm2 <> "" Then
.attachments.Add Attchm2
Else
End If
If Attchm3 <> "" Then
.attachments.Add Attchm3
Else
End If
.display
.send
End With
cell.Offset(0, 5).Value = "EMAIL has been Sent"
End If
Next
Set Email = Nothing
Set outlookApp = Nothing
End Sub
Pls i want to know like if want to search a particular column of data on the list box to display, highlight and can double click the data on the list box and finally diplay on form too. Thank you.
ReplyDeleteThanks
ReplyDeleteI just asked a question like I never linked any path I direct link the pdf file with link . Is it possible?