Results 1 to 23 of 23

EXCEL VBA send dynamic emails messages based on trigger column

Threaded View

  1. #7
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    i've reconstructed what i think your spreadsheet looks like and added some sample code of what you could possibly do
    Sub EmailTest()
    
        Dim outlookapp As Object 'mailapp object
        Dim Outlookmailitem As Object 'mailitem object
        Dim Icounter As Integer 'counter for loop
        Dim MailDest As String 'email destination
        Dim Mess As String 'message
        Dim Subject As String 'subject
        
        Set outlookapp = CreateObject("outlook.application")
        Set Outlookmailitem = outlookapp.CreateItem(0)
        
        With Outlookmailitem
            
            MailDest = ""
            For Icounter = 2 To WorksheetFunction.CountA(Columns(1))
                If MailDest = "" And Cells(Icounter, 5) = "Captured" Then
                    Mess = Cells(Icounter, 4).Value
                    MailDest = Cells(Icounter, 1).Value
                    Subject = Cells(Icounter, 2).Value & " - " & Cells(Icounter, 3).Value
                
                ElseIf MailDest <> "" And Cells(Icounter, 5) = "Captured" Then
                    Mess = Mess & vbNewLine & Cells(Icounter, 4).Value
                    MailDest = MailDest & ";" & Cells(Icounter, 1).Value
                    Subject = Subject & " | " & Cells(Icounter, 2).Value & " - " & Cells(Icounter, 3).Value
                
                End If
            Next Icounter
            
            .To = MailDest 'not sure why you were using .cc instead of .to
            .Subject = Subject
            .Body = "List of Messages" & vbNewLine & vbNewLine & Mess & vbNewLine & vbNewLine & "Yours Sincerly," & _
                vbNewLine & "McJonesy" 'change to however you want email to be displayed, use vbnewline to enter new line
            .display '.Send change to .send for automatic send, use .display when debugging
            
        End With
        
        Set Outlookmailitem = Nothing
        Set outlookapp = Nothing
        
    End Sub
    see if you does what you want
    ps i changed .send to .display so it doesnt automatically send out emails while you are debugging
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel vba to auto-send customer emails (duplicate emails issue)
    By nadz84 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-29-2015, 10:08 AM
  2. Replies: 2
    Last Post: 12-19-2014, 11:28 AM
  3. Send Emails once expiry date is reached, and generate report based on emails sent
    By demonicscorpion in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2014, 05:36 AM
  4. [SOLVED] Need help getting excel to send automatic emails based on cell value
    By Quito in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-11-2014, 07:09 AM
  5. Automatically send an email based on the value of a cell and/or trigger date
    By psn.arya in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-05-2013, 06:17 PM
  6. Send Emails based on cell value
    By kaki1956 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2010, 08:28 PM
  7. Sending macro emails using excel: Send emails with their passwords.
    By loveisblind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 03:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1