+ Reply to Thread
Results 1 to 10 of 10

Send E-Mail Using VBA To E-Mail Lists On Excel

Hybrid View

alulla Send E-Mail Using VBA To... 06-18-2013, 09:49 AM
Tinbendr Re: Send E-Mail Using VBA To... 06-18-2013, 11:27 AM
alulla Re: Send E-Mail Using VBA To... 06-18-2013, 11:40 AM
Tinbendr Re: Send E-Mail Using VBA To... 06-18-2013, 11:56 AM
alulla Re: Send E-Mail Using VBA To... 06-18-2013, 12:05 PM
nickmax1 Re: Send E-Mail Using VBA To... 06-18-2013, 11:44 AM
alulla Re: Send E-Mail Using VBA To... 06-18-2013, 11:57 AM
nickmax1 Re: Send E-Mail Using VBA To... 06-18-2013, 12:04 PM
alulla Re: Send E-Mail Using VBA To... 06-18-2013, 03:40 PM
rollis13 Re: Send E-Mail Using VBA To... 06-18-2013, 04:08 PM
  1. #1
    Registered User
    Join Date
    06-05-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    39

    Send E-Mail Using VBA To E-Mail Lists On Excel

    Have 90% of my VBA code written, just need to add the following. My macro pretty much runs and If Statement and if a certain condition applies, it will email it to a certain address. What I need it to do is to run the if statement, and if it meets the certain condition to email it to a list of 4-5 emails (maybe even more) which is in the same workbook but a different tab entitled "Email List".

    Here is a piece of the code I have written out currently

    If IsEmpty(Range("H4")) Then
    Else
    ActiveSheet.Range("G3", ActiveSheet.Range("K3").End(xlDown)).Select

    ActiveWorkbook.EnvelopeVisible = True
    With ActiveSheet.MailEnvelope
    .Item.To = "email1@gmail.com" & "; email2@outlook.com"
    .Item.Subject = "Allocations - BNP" & Format(Date, " mm/dd/yyyy")
    .Item.Send
    End With
    End If

    and here is the tab Email List which a list of the emails I need for say 2 of those if statements.

    Untitled.png
    Last edited by alulla; 06-18-2013 at 11:04 AM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel

    Dim aCell As Range
    Dim eTo As String
    If IsEmpty(Range("H4")) Then
    Else
        ActiveSheet.Range("G3", ActiveSheet.Range("K3").End(xlDown)).Select
        
        ActiveWorkbook.EnvelopeVisible = True
        With ActiveSheet.MailEnvelope
            For Each aCell In ActiveSheet.Range("B3:B5", "E3:E6")
                If aCell <> "" Then
                    eTo = eTo & aCell & ";"
                End If
            Next
            eTo = Left(eTo, Len(eTo) - 1)
        
            .Item.To = eTo
            .Item.Subject = "Allocations - BNP" & Format(Date, " mm/dd/yyyy")
            .Item.Send
        End With
    End If
    Please put code in CODE tags. (The Hash # symbol.)
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    06-05-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel

    Quote Originally Posted by Tinbendr View Post
    Dim aCell As Range
    Dim eTo As String
    If IsEmpty(Range("H4")) Then
    Else
        ActiveSheet.Range("G3", ActiveSheet.Range("K3").End(xlDown)).Select
        
        ActiveWorkbook.EnvelopeVisible = True
        With ActiveSheet.MailEnvelope
            For Each aCell In ActiveSheet.Range("B3:B5", "E3:E6")
                If aCell <> "" Then
                    eTo = eTo & aCell & ";"
                End If
            Next
            eTo = Left(eTo, Len(eTo) - 1)
        
            .Item.To = eTo
            .Item.Subject = "Allocations - BNP" & Format(Date, " mm/dd/yyyy")
            .Item.Send
        End With
    End If
    Please put code in CODE tags. (The Hash # symbol.)
    Hey Tinbendr, Thank you for the help. This is not exactly what I needed. If you could, could you help come up with a code which would select the emails from a different work sheet in the same work book? The work sheet name will be "Email List"...also you have mentioned specific cells....some of the email lists will contain like 7-8 emails and there are 8 email lists in total while you've only referenced two. Please advise and thanks for the help.

  4. #4
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,138

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel

    Quote Originally Posted by alulla View Post
    This is not exactly what I needed.
    I thought you might be able to change the sheet reference.

    For Each aCell In Worksheets("Email List").Range("B3:B5", "E3:E6")
    ...also you have mentioned specific cells....some of the email lists will contain like 7-8 emails and there are 8 email lists in total while you've only referenced two.
    Just add the range reference as required separated by a comma.
    ... .Range("B3:B5", "E3:E6")
    If you need to select a certain range reference then you are going to have to tell me how you you want to accomplish that.

  5. #5
    Registered User
    Join Date
    06-05-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel

    Quote Originally Posted by Tinbendr View Post
    I thought you might be able to change the sheet reference.

    For Each aCell In Worksheets("Email List").Range("B3:B5", "E3:E6")
    Just add the range reference as required separated by a comma.
    ... .Range("B3:B5", "E3:E6")
    If you need to select a certain range reference then you are going to have to tell me how you you want to accomplish that.
    This seems really close to working. I just edited it to yours, but unfortunately it's only sending to the second email on my list and not the first? It seems to just skip over the first email. Here's what I have.

    Sub Send_Range()
       Dim aCell As Range
       Dim eTo As String
       If IsEmpty(Range("B4")) Then
       Else
          ActiveSheet.Range("a3", ActiveSheet.Range("e3").End(xlDown)).Select
          ActiveWorkbook.EnvelopeVisible = True
       With ActiveSheet.MailEnvelope
        For Each aCell In Worksheets("Email List").Range("B3").End(xlDown)
            If aCell <> "" Then
                eTo = eTo & aCell & ";"
            End If
        Next
        eTo = Left(eTo, Len(eTo) - 1)
          .Item.To = eTo
          .Item.Subject = "Allocations -  Barclays" & Format(Date, " mm/dd/yyyy")
          .Item.Send
       End With
       End If

  6. #6
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel


  7. #7
    Registered User
    Join Date
    06-05-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel

    Quote Originally Posted by nickmax1 View Post
    I changed it to this and it doesn't work.

    Sub Send_Range()
       Dim eTo As String
       
       ' Select the range of cells on the active worksheet.
       If IsEmpty(Range("B4")) Then
       Else
          ActiveSheet.Range("a3", ActiveSheet.Range("e3").End(xlDown)).Select
       ' Show the envelope on the ActiveWorkbook.
       ActiveWorkbook.EnvelopeVisible = True
       ' Set the optional introduction field thats adds
       ' some header text to the email body. It also sets
       ' the To and Subject lines. Finally the message
       ' is sent.
       With ActiveSheet.MailEnvelope
    
        eTo = Join(Application.Transpose(Worksheetse("Email List").Range("B3").End(xlDown).Value), ";")
        
          .Item.To = eTo
          .Item.Subject = "Allocations -  Barclays" & Format(Date, " mm/dd/yyyy")
          .Item.Send
       End With
       End If

  8. #8
    Valued Forum Contributor
    Join Date
    08-10-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    721

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel

    Do you have a sheet called "Email List" , and the email list starts at B3 in that sheet?

    What error do you get?

    replace your
     eTo = Join(Application.Transpose(Worksheetse("Email List").Range("B3").End(xlDown).Value), ";")
    with

     eTo = Join(Application.Transpose(Worksheets("Email List").Range("B3").End(xlDown).Value), ";")
    you made a typo - try that

  9. #9
    Registered User
    Join Date
    06-05-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel

    Anyone? Still stuck on this

  10. #10
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Send E-Mail Using VBA To E-Mail Lists On Excel


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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