Hello, I have a code I had found a while back that can email recipients. It is as follows:
This code emails a group of people and then saves a special-named copy in a folder. The email list currently doesn't have any CC'd recipients, but I'd like to potentially change that. If this is doable, I'm wondering what alterations could be made to this code to include the CC'd recipients(regular recipients are pulled from cell W1 and CC'd would be pulled from cell W2) if one or more cells in column E contain the phrase "ZZZ-Unexcused Absence". So basically if none of the cells contain that phrase, it just emails the normal listing in the TO field, but if column E does contain that value, then it would email the TO recipients AND the CC recipients. Thanks for your time.
VBA Code:
Sub savesheet()
Dim Name As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveWorkbook.Save
EmailWBAttached
Name = "\\Sample\" & _
Format(Now(), "mmddyy") & " " & "Perishable 1ST SHIFT ABSENTEE BLANK (1ST SHIFT)" & ".xlsm"
ActiveSheet.SaveAs Filename:=Name, FileFormat:=52
Workbooks.Open "\\Sample\1ST SHIFT ABSENTEE REPORT.xlsm"
ThisWorkbook.Activate
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub EmailWBAttached()
ActiveWorkbook.Save
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.Display
.HTMLBody = "<BODY style=font-size:11pt;font-family:Calibri>" & "Attached is the attendance sheet (or revision) to 1st Shift Perishable.<br>" & "</BODY>" & .HTMLBody
.To = ActiveSheet.Range("W2").Value
.CC = ""
.BCC = ""
.Subject = "1st Shift Attendance: " & Format(Now(), "mm.dd.yy")
.Attachments.Add Application.ActiveWorkbook.FullName
'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub