Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: how to send each row by email

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0

    how to send each row by email

    hi,

    In my excel document from column A to G in every single row, there are private datas of in each person. For example, the first row consists of person A's private data. Second row is only about person B, etc.. In column I , their email addresses exist. What I am trying to do is to send each row as an email to related person. Your VBA code help would be highly appreciated.

    Regards
    Baris

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi Baris,

    Welcome to ExcelFox !!!

    Try this

    Code:
    Sub SendEmailRowByRow()
        
        Dim OutApp      As Object
        Dim OutMail     As Object
        Dim strBody     As String
        Dim LastRow     As Long
        Dim eMailIDs, i As Long
        Dim varBody
        
        Const StartRow  As Long = 2     '<<< adjust to suit
        
        
        If Not Application.Intersect(Range("I:I"), ActiveSheet.UsedRange) Is Nothing Then
            
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
            
            LastRow = Range("I" & Rows.Count).End(xlUp).Row
            
            eMailIDs = Range("I" & StartRow).Resize(LastRow - StartRow + 1)
            
            For i = 1 To UBound(eMailIDs, 1)
                varBody = Range("a" & StartRow + i - 1).Resize(, 7).Value
                strBody = Join(Application.Transpose(Application.Transpose(varBody)), vbTab)
                On Error Resume Next
                With OutMail
                    .To = eMailIDs(i, 1) 'email from corresponding row goes here
                    .CC = ""
                    .BCC = ""
                    .Subject = "Subject"    '<< adjust subject line
                    .Body = strBody
                    'You can add a file like this
                    '.Attachments.Add ("C:\")
                    .Display
                    'or use .Send
    '                .Send
                End With
                On Error GoTo 0
            Next
        End If
        
        Set OutMail = Nothing
        Set OutApp = Nothing
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    Quote Originally Posted by Admin View Post
    Hi Baris,

    Welcome to ExcelFox !!!

    Try this
    Hi,
    Thanks for the code but it sends email to the last person in the list only. (the last row I mean)
    If there are twenty individuals, how can we change it?

    Thanks in advance
    Baris

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    No, it'll send emails to everyone in Col I mentioned, since we are looping Col I for email address.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    Only the last receipent received an email message with that code.

  6. #6
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    sorry for questions. Is this ubound formula correct?

    For i = 1 To UBound(eMailIDs, 1)

    Debug error pops out.

  7. #7
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    The error comes because the there is no data in Col I. Check whether your email ids are in Col I ?

    Could you please attach a sample workbook ? Feel free to put dummy data in the attachment.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  8. #8
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    Hi,
    It's done..

    Thanks
    Baris
    Attached Files Attached Files

  9. #9
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi,

    Your StartRow should be 1.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  10. #10
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    Quote Originally Posted by Admin View Post
    Hi,

    Your StartRow should be 1.
    Hi,
    Outlook seems like as if it is going to send email messages to all individuals but only one email message window comes out. When I click to send button, i see only one message in "sent items" box. VB code sends email to last person only.


    fyi
    Baris
    Last edited by BARIS; 08-24-2012 at 02:09 PM.

Similar Threads

  1. Replies: 17
    Last Post: 07-15-2013, 09:56 PM
  2. Replies: 2
    Last Post: 05-23-2013, 08:08 AM
  3. How To Send Outlook Email Using VBA
    By mfaisalrazzak in forum Excel Help
    Replies: 7
    Last Post: 03-03-2013, 03:09 AM
  4. Send Outlook Email With Word Document
    By Murali K in forum Excel Help
    Replies: 2
    Last Post: 06-27-2012, 08:42 PM
  5. Send Lotus Notes Email Using VBA
    By ramakrishnan in forum Excel Help
    Replies: 1
    Last Post: 09-08-2011, 09:00 AM

Posting Permissions

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