Good Afternoon,
My expertise of VBA is still intermediate so any help concerning this matter is much appreciated.
I have created a VBA Script (As per Below) to send an email to an individual recipient however I'm finding it difficult to ascertain the means to send an email to a particular user depending on the data in a given cell.
For instance if Target.Cell.Offset (0,-2).value = A then an email needs to be send to [email protected]
There are 8 alternative variables, each of which given an alternative email address.
Please see the below script.
Please could someone provide me with a solution to this problem.
Thank you in advance.
Private Sub SendEmail(EmailSubject, EmailBody)
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim MyReci As Outlook.Recipient
Set OutApp = New Outlook.Application
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.Recipients.Add ("x")
.Subject = Emailubject
.Body = EmailBody
.CC = ("[email protected]")
.Display
End With
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Value = "" Then
Target.Value = "ü"
Target.Font.Name = "Wingdings"
End If
If Target.Cells.Offset(0, -2).Value = "Open" Then
Answer = MsgBox("Distribute email?", vbYesNo, Cells(Target.Row, 3).Value)
If Answer = vbYes Then
EmailSubject = "PIR Task"
EmailBody = Target.Cells.Offset(0, -13).Value & vbNewLine & vbNewLine & "ACTION: " & Target.Cells.Offset(0, -7) & vbNewLine & vbNewLine & "DUE DATE:" & Target.Cells.Offset(0, -5).Value
SendEmail EmailSubject, EmailBody
Else
Exit Sub
End If
End If
End Sub
Bookmarks