Skip to content

Instantly share code, notes, and snippets.

@adrielAd
Created February 9, 2022 12:32
Show Gist options
  • Save adrielAd/7e13b968c69170101d1799ba0dc1426e to your computer and use it in GitHub Desktop.
Save adrielAd/7e13b968c69170101d1799ba0dc1426e to your computer and use it in GitHub Desktop.
Sub EmailAll()
Dim oApp As Object
Dim oMail As Object
Dim SendToName As String
Dim theSubject As String
Dim theBody As String
For Each c In Selection 'loop through (manually) selected records
'''For each row in selection, collect the key parts of
'''the email message from the Table
SendToName = Range("C" & c.Row)
theSubject = Range("H" & c.Row)
theBody = Range("I" & c.Row)
'''Compose emails for each selected record
'''Set object variables.
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
'''Compose the customized message
With oMail
.To = SendToName
.Subject = theSubject
.Body = theBody
''' If you want to send emails automatically, use the Send option.
''' If you want to generate draft emails and review before sending, use the Display option.
''' Do not use both!
'''To activate your chosen option: Remove the single quote from the beginning of the code line, then
'''add the single quote back to the option you didn't choose
.Display
'.Send
End With
Next c
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment