Hey
We have a database which we update daily and need to send an email to separate people based on the input. My code check selected cells per rows creates the emails. My problem is we need to manually check if we select cells from the same person otherwise we send it to the wrong person. For Instance I select 2 rows, one belonging to PersonA, one to PersonB, the code only makes one mail for PersonA, but with both inputs.
What we need is something like this. If I select 6 rows, 4 belonging to PersonA, 2 belonging to PersonB the code generates 2 emails and puts the 4 row's input to PersonA email and vica versa
Is this doable?
Thank you
We have a database which we update daily and need to send an email to separate people based on the input. My code check selected cells per rows creates the emails. My problem is we need to manually check if we select cells from the same person otherwise we send it to the wrong person. For Instance I select 2 rows, one belonging to PersonA, one to PersonB, the code only makes one mail for PersonA, but with both inputs.
What we need is something like this. If I select 6 rows, 4 belonging to PersonA, 2 belonging to PersonB the code generates 2 emails and puts the 4 row's input to PersonA email and vica versa
Is this doable?
Thank you
VBA Code:
Sub ExcelToOutlookSR()
Dim mApp As Object, mMail As Object
Dim SendToMail As String, MailSubject As String, mMailbody As String, TimeE As String, signature As String
Dim TimeS As Date
Set mApp = CreateObject("Outlook.Application")
Set mMail = Outlook.CreateItem(0)
With mMail
.display
End With
sig = mMail.HTMLBody
For Each r In Selection
SendToMail = Range("H" & r.row)
MailSubject = "data" & Range("B" & r.row)
TimeS = Range("C" & r.row)
TimeE = Range("M" & r.row)
mMailbody = "lots of data" & mMailbody
Range("O" & r.row).Interior.Color = RGB(153, 204, 0)
Next r
mMailbody = mMailbody & sig
With mMail
.SentOnBehalfOfName = ""
.To = SendToMail
.CC = ""
.Subject = MailSubject
.HTMLBody = mMailbody
.display
End With
End Sub