Advertisement
dave3009

MayMailer

Apr 6th, 2023
1,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Sub BulkEmail()
  4. Dim EmailList As Range
  5. Dim EmailAddr As Range
  6. Dim lst As Long
  7.  
  8. lst = Sheet1.Range("C" & Rows.Count).End(xlUp).Row
  9.  
  10. Set EmailList = Sheet1.Range("C1:C" & lst)
  11.  
  12. For Each EmailAddr In EmailList
  13.     MailMacro EmailAddr.Value
  14. Next EmailAddr
  15.  
  16. End Sub
  17.  
  18.  
  19. Sub MailMacro(outTo As String)
  20. Dim oApp As Outlook.Application
  21. Dim oMail As MailItem
  22.  
  23.     Set oApp = New Outlook.Application
  24.     Set oMail = oApp.CreateItem(olMailItem)
  25.        
  26.         With oMail
  27.            
  28.             .To = outTo
  29.             .Subject = "Message Subject"
  30.             .Body = BodyText
  31.             .Display ' or .Send
  32.        
  33.         End With
  34.    
  35.     Set oMail = Nothing
  36.     Set oApp = Nothing
  37. End Sub
  38.  
  39. Function BodyText() As String
  40.  
  41.     BodyText = BodyText & "Hi" & vbNewLine
  42.     BodyText = BodyText & "This is an email" & vbNewLine
  43.     BodyText = BodyText & "Thanks" & vbNewLine
  44.     BodyText = BodyText & "Me" & vbNewLine
  45.  
  46. End Function
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement