MikoSDS

New Member
Joined
Feb 22, 2019
Messages
24
Hello All,


I have a small problem but I have no idea how to solve this, so I want to send a few emails to one person, just not one by one like in the code, but as package or something.


For example:


Mail to Mr.A where's assigned a few positions should be send in one mail. In mailbody will be text + the numbers, which are assigned to him, but subject will be only "Reminder". But for Mr.BB, where's only one position the number should be send in subject + the "Reminder" like in the code.

Column A: Column B:

Mr.A@mail.com#10288014
Mr.A@mail.com#10288015
Mr.A@mail.com#10288016
Mr.A@mail.com#10288017
Mr.A@mail.com#10288018
Mr.BB@mail.com#10288019
Mr.CC@mail.com#10288020
Mr.DD@mail.com#10288021
Mr.EE@mail.com#10288022
Mr.FF@mail.com#10288023

<colgroup><col><col></colgroup><tbody>
</tbody>

Code:
   LR = Cells(Rows.Count, 2).End(xlUp).Row
    For x = 2 To LR
    
        nr = nr + 1
        
        MailFrom = Sheets("Start").Cells(2, 2).Value
        MailTo = Range("A" & x).Value
        MailSubject = "Reminder " & Range("B" & x).Value
        MailBody = Sheets("Start").Cells(5, 2)
        
            Set OutlookApp = CreateObject("Outlook.application")
            Set OutlookMailitem = OutlookApp.CreateItem(0)
            
            With OutlookMailitem
                .Display
                .SentOnBehalfOfName = MailFrom
                .To = MailTo
                .Subject = MailSubject
                .Body = MailBody
                .Send
            End With
            
            Set OutlookMail = Nothing
            Set OutlookApp = Nothing
    Next x

Thank you all for help.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try this


Code:
Sub test_mail()
    Dim OutlookMailitem As Object
    Dim MailFrom As String, MailTo As String, MailSubject As String, MailBody As String
    Dim ant As String, cad As String
    Dim lr As Long, i As Long, n As Long
    
    ant = Cells(2, "A").Value
    cad = ""
    n = 0
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
    For i = 2 To lr + 1
        If ant <> Cells(i, "A").Value Then
            Set OutlookMailitem = CreateObject("Outlook.application").CreateItem(0)
            
            MailTo = ant
            MailFrom = Sheets("Start").Cells(2, 2).Value
            MailBody = Sheets("Start").Cells(5, 2).Value
            MailSubject = "Reminder "
            If n = 1 Then MailSubject = MailSubject & cad Else MailBody = MailBody & " " & cad
            
            With OutlookMailitem
                .SentOnBehalfOfName = MailFrom
                .To = MailTo
                .Subject = MailSubject
                .Body = MailBody
                .Display
                .Send
            End With
            
            Set OutlookMailitem = Nothing
            cad = ""
            n = 0
        End If
        n = n + 1
        ant = Cells(i, "A").Value
        cad = cad & " " & Cells(i, "B").Value
    Next
        
    MsgBox "End"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,868
Messages
6,122,005
Members
449,059
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top