miling list with a standard email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sal21
    New Member
    • Jun 2006
    • 27

    miling list with a standard email

    I have an mail with a stabdard subject and standard boy text.
    Now in ecel sheet have 2 column:

    Column A named MAIL (with email address)
    Column B named BODY_TEXT

    I need to loop column A until last cell is blank and send e mail uing the same template saved in c:\mydir\

    How to????
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    This will send Emails to the addresses in column A with the text in the "Document.t xt" and replace the values from column B, C and D in the text. (see also attachments)

    Code:
    Sub Send_All_Mails()
    Dim FF As Long
    Dim TEMPLATE, MAILTEXT, Email_Subject, Email_Send_From, Email_Send_To, _
            Email_Cc, Email_Bcc, Email_Body As String
    Dim Mail_Object, Mail_Single As Variant
        FF = FreeFile
        On Error GoTo Error_Loading
        Open ThisWorkbook.Path & "\document.txt" For Binary As #FF
        '  Allocate a buffer equal in size to the file
        '  (see LOF function) so that the Get statement
        '  can stuff text from the file into it.
        TEMPLATE = Space(LOF(FF))
        Get #FF, , TEMPLATE
        Close #FF
        Range("A1").Activate
        Do Until ActiveCell.Value = ""
            '§ create mail text
            MAILTEXT = TEMPLATE
            MAILTEXT = Replace(MAILTEXT, "##1##", ActiveCell.Offset(0, 1).Value)
            MAILTEXT = Replace(MAILTEXT, "##2##", ActiveCell.Offset(0, 2).Value)
            MAILTEXT = Replace(MAILTEXT, "##3##", ActiveCell.Offset(0, 3).Value)
            '§ send mail
            Email_Subject = "Trying to send email using VBA"
            Email_Send_From = "guido.geurs@gmail.com"
            Email_Send_To = ActiveCell.Value
            Email_Cc = ""
            Email_Bcc = ""
            Email_Body = MAILTEXT
            On Error GoTo debugs
            Set Mail_Object = CreateObject("Outlook.Application")
            Set Mail_Single = Mail_Object.CreateItem(0)
            With Mail_Single
                .Subject = Email_Subject
                .To = Email_Send_To
                .cc = Email_Cc
                .BCC = Email_Bcc
                .Body = Email_Body
                .Send
            End With
            ActiveCell.Offset(1, 0).Activate
        Loop
    Exit Sub
    debugs:
        If Err.Description <> "" Then MsgBox Err.Description
    Exit Sub
    Error_Loading:
       Close #FF
       MsgBox ("Error loading !")
    End Sub
    Attached Files

    Comment

    Working...