How to send mail to multiple mail IDs from Out look using outlook

PRAKVIVA

New Member
Joined
Sep 23, 2017
Messages
1
Hi,

I am stuck with one issue in Excel. I need to send action items to specific mail IDs through the excel :-

Column A - has email ID
Column B - has Subject of Mail
Column C - has Body of Mail

Thank you for your help...
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Here's one method:

Code:
Dim m_objOutlookApp As Object

Public Sub SendEmails()
  Dim strEmailAddress As String
  Dim strEmailSubject As String
  Dim strEmailBody As String
  Dim wksSource As Worksheet
  Dim j As Long
  
  On Error Resume Next
' Use existing Outlook instance if applicable
  Set m_objOutlookApp = GetObject(, "Outlook.Application")
  
  If Err.Number <> 0 Then
    On Error GoTo ErrHandler
  ' Otherwise create new instance
    Set m_objOutlookApp = CreateObject("Outlook.Application")
  End If
  
  On Error GoTo ErrHandler
  Set wksSource = ThisWorkbook.Sheets("Sheet1") ' Sheet containing the data
  
' Assume column A is email address, B is subject, C is body.
' Assume headers in 1st row, data starts in 2nd row.
  For j = 2 To wksSource.Cells(wksSource.Rows.Count, "A").End(xlUp).Row
    strEmailAddress = wksSource.Cells(j, "A").Value
    strEmailSubject = wksSource.Cells(j, "B").Value
    strEmailBody = wksSource.Cells(j, "C").Value
    
    On Error GoTo NextRow
    Call SendEmail(strEmailAddress, strEmailSubject, strEmailBody)
NextRow:
  ' Can handle emailing errors here
    On Error GoTo ErrHandler
  Next j
  
ExitProc:
  Set m_objOutlookApp = Nothing
  Set wksSource = Nothing
  Exit Sub
  
ErrHandler:
  MsgBox Err.Description, vbExclamation
  Resume ExitProc
End Sub

Private Sub SendEmail(strEmailAddress As String, _
                      strEmailSubject As String, _
                      strEmailBody As String)
  
  Const olMailItem = 0
  Dim objMailItem As Object
  
  Set objMailItem = m_objOutlookApp.CreateItem(olMailItem)
  objMailItem.To = strEmailAddress
  objMailItem.Subject = strEmailSubject
  objMailItem.Body = strEmailBody
  objMailItem.Display
' Can replace previous line with: objMailItem.Send
  Set objMailItem = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top