+ Reply to Thread
Results 1 to 4 of 4

Send Email Based on Cell Values

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2016
    Location
    oregon
    MS-Off Ver
    excel 2013
    Posts
    15

    Send Email Based on Cell Values

    I'm trying to using an If Statement with VBA but have never done it before.
    IF C3="A" in the active excel workbook, send email to "Person A" & cc "Distribution List A". If not send email to "Person B" & cc "Distribution B".
    Code shown below. Thanks for your help!!!!!!!



    Dim OutApp As Object
        Dim OutMail As Object
         
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
         
        On Error Resume Next
        With OutMail
            .To = "Person A"
            .Cc = "Distribution List A"
            '.BCC = ""
            .Subject = "My Report"
            .Body = "Report has been included as an attachment."
            .Attachments.Add ActiveWorkbook.FullName
            .Display
        End With
        On Error GoTo 0
        
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    Last edited by weeblegobble; 02-18-2018 at 05:28 PM.

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Send Email Based on Cell Values

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Before proceeding further in this thread, click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Now to your question:
    You may try something like this.....
    Dim OutApp As Object
    Dim OutMail As Object
    Dim emailTO As String, emailCC As String
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
    
    If Range("C3").Value = "A" Then
        emailTO = "PersonA@email.com"               'replace with actual email
        emailCC = "DistributionlistA@email.com"     'replace with actual email
    Else
        emailTO = "PersonB@email.com"               'replace with actual email
        emailCC = "DistributionlistB@email.com"     'replace with actual email
    End If
    On Error Resume Next
    With OutMail
    .to = emailTO
    .CC = emailCC
    '.BCC = ""
    .Subject = "My Report"
    .Body = "Report has been included as an attachment."
    .Attachments.Add ActiveWorkbook.FullName
    .Display
    End With
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    02-22-2016
    Location
    oregon
    MS-Off Ver
    excel 2013
    Posts
    15

    Re: Send Email Based on Cell Values

    Thank you thank you!! Worked like a charm.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Send Email Based on Cell Values

    You're welcome!
    Thanks for the rep and adding the code tag as well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to send an email via Lotus Notes to an employee based upon cell values
    By kodonnell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-02-2015, 12:43 PM
  2. Workflow with signatures (if cell=x then send email, if signed then send email)
    By Kate2811 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2014, 05:37 AM
  3. Send email to address based on cell value
    By shiftyspina in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-12-2014, 03:06 PM
  4. Send email based on address in a cell
    By behnam in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-19-2013, 02:53 PM
  5. excel send an email based on cell value (Date)
    By Arpanasiaworld in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-26-2013, 07:59 PM
  6. Send email depending on cell values in selected row
    By tandridge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2011, 10:15 AM
  7. send email message based on cell conditions
    By danusko in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 02:24 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