Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: how to send each row by email

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

    try this one. Also put this code in a standard module, not in class module.

    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 = 1     '<<< adjust to suit
        
        
        If Not Application.Intersect(Range("I:I"), ActiveSheet.UsedRange) Is Nothing Then
            
            LastRow = Range("I" & Rows.Count).End(xlUp).Row
            
            eMailIDs = Range("I" & StartRow).Resize(LastRow - StartRow + 1)
            
            For i = 1 To UBound(eMailIDs, 1)
                
                Set OutApp = CreateObject("Outlook.Application")
                Set OutMail = OutApp.CreateItem(0)
                
                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 = "Expired account notification"    '<< adjust subject line
                    .Body = strBody
                    'You can add a file like this
                    '.Attachments.Add ("C:\")
    '                .Display
                    .Send
                    Application.Wait Now + TimeSerial(0, 0, 3)
                    Set OutMail = Nothing
                    Set OutApp = Nothing
                End With
                On Error GoTo 0
            Next
        End If
        
    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)

  2. #12
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    It works flawless!
    Thank you so much!

    Baris
    Last edited by Admin; 08-24-2012 at 06:25 PM.

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

    Thanks for the feedback.
    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)

  4. #14
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    Hi Again,
    How can I add cell C(i) to subject line into each email?
    What I need to print to subject field for the first line is, for example, "customer11, expired account" etc..
    Here is the script and the excel file I run in my pc:

    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 = 1     '<<< adjust to suit
        
        
        If Not Application.Intersect(Range("I:I"), ActiveSheet.UsedRange) Is Nothing Then
            
            LastRow = Range("I" & Rows.Count).End(xlUp).Row
            
            eMailIDs = Range("I" & StartRow).Resize(LastRow - StartRow + 1)
            
            For i = 1 To UBound(eMailIDs, 1)
                
                Set OutApp = CreateObject("Outlook.Application")
                Set OutMail = OutApp.CreateItem(0)
                
                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 = "Expired account notification"    '<< adjust subject line
                    .Body = strBody
                    'You can add a file like this
                    '.Attachments.Add ("C:\")
    '                .Display
                    .Send
                    Application.Wait Now + TimeSerial(0, 0, 3)
                    Set OutMail = Nothing
                    Set OutApp = Nothing
                End With
                On Error GoTo 0
            Next
        End If
        
    End Sub
    Attached Files Attached Files

  5. #15
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Code:
    .Subject = varBody(1, 3) & ", Expired account notification"
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  6. #16
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    HI

    like

    Code:
    .Subject = Range("C" & i).Value & ", Expired account notification"
    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)

  7. #17
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    Thanks to both of you Gentlemen.
    I have checked the second one only and works smoothly.

    Quote Originally Posted by Excel Fox View Post
    Code:
    .Subject = varBody(1, 3) & ", Expired account notification"
    Quote Originally Posted by Admin View Post
    HI

    like

    Code:
    .Subject = Range("C" & i).Value & ", Expired account notification"
    Thanks
    Baris

  8. #18
    Junior Member
    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Hi, this is my first time using excelfox and I'm fairly new to VBA

    I would like to add a modified version of this code if you can help me out. I have already written code in an outlook macro that scrapes off excel attachments from emails in a specific folder, savesthe attachments to a folder on my computer, opens the saved attachments in excel, and filters the excel spreadsheet.

    Now, I need to map the person's name in column C to specific email adresses and send a message to them if column N has a value less than 5.

    Your help would be much appreciated!

  9. #19
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    So in your attachment, you can check column N like this

    Code:
    If Range("N" & lngRow).Value < 5 Then
    'your code to send the message
    'in the To part, use Range("C" & lngRow).Value
    Else
    'Do Nothing
    End if
    You'll have to make the adjustments..... if it's not clear, post back with a sample of the excel saved attachments
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  10. #20
    Junior Member
    Join Date
    Aug 2012
    Posts
    14
    Rep Power
    0
    Dear Excel fox and Admin,
    Last evening I sent 120 email messages with just one click.
    Thanks for your help

    Now, I have another question. If I should open a new thread, let me know.
    I would like to reply my email messages automatically.
    When I receive an email which includes "information" phrase in subject line shall be replied with the same excel file which I uploaded earlier to this board. In addition to replying every single email, it will print receipent's email address into excel file to right side cell of related line.

    Thanks in advance
    Baris

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
  •