Last active
November 12, 2021 16:53
-
-
Save Se7enSquared/cc665c3049f59b53b7932318ef744521 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------------------- | |
' Sub: SendEmail | |
' Purpose: Sends an email through Outlook | |
' Params: | |
' Subject: String: email subject | |
' to_list: Stirng: semi-colon seperated list of recipients | |
' cc_list: String: semi-colon seperated list of cc | |
' body: String: email body | |
' Last Update: 3/5/2021 | |
' Author: Gray | |
'------------------------------------------------------------- | |
Public Sub SendEmailWithThisWorkbookAttached(ByVal subject As String, ByVal to_list As String, ByVal cc_list As String, ByVal body As String, Optional ByVal has_attachment As Boolean = True) | |
On Error GoTo catch_error | |
Dim email_app As Outlook.Application | |
Set email_app = New Outlook.Application | |
Dim email_item As Outlook.MailItem | |
Set email_item = email_app.CreateItem(olMailItem) | |
email_item.To = to_list | |
email_item.CC = cc_list | |
email_item.subject = subject | |
email_item.HTMLBody = body | |
If has_attachment Then | |
ThisWorkbook.Save | |
email_item.Attachments.Add ThisWorkbook.FullName | |
End If | |
email_item.Send | |
Exit Sub | |
catch_error: | |
If testing_mode = True Then GoTo debug_error | |
Libraries.LogErrorMessageToXls "Email send has failed in " & ThisWorkbook.Name, "Macro error: " & Err.Description & " in SendEmail subroutine", "https://hp.sharepoint.com/teams/WS OEM PRGM/OCMS Reports/AutomationErrorLogs.xlsx", "ErrorLog", "tbl_ErrorLog" | |
ThisWorkbook.Close | |
debug_error: | |
Application.DisplayAlerts = True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment