Hello and thanks for helping. I am very new to VBA. I have a spreadsheet that needs to be emailed to different reviewers at different intervals based on the text in the cell. For example, if column O = "Y" then send email to userA@outlook.com; if column P = "Y" then send to userB@outlook.com; if column Q = "Y" then send to userC@outlook.com. So far I have the following, but don't know how to add the other variables without getting errors.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Address = "O2:O26" And Target.Value <> "" Then
CreateMail
End If
End Sub
Sub CreateMail()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "userA@outlook.com"
.CC = ""
.BCC = ""
.Subject = "New document ready for review"
.Body = "Hi, There is a new document ready for you to review."
.Attachments.Add ("C:\")
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Last edited by a moderator: