Sub Email _
(sTo As String, sSub As String, _
sHTML As String, Optional sAttach As Variant, _
Optional sAction As String = "Display", _
Optional sCCs As String, Optional sSender As String)
'v1.49 31 Mar 2023
'Crafted by Ron DeBruin, Wookiee at MrExcel, and ChatGPT
'https://www.RONDEBRUIN.nl/win/s1/outlook/signature.htm
'Declare Variables
Dim lngLoop As Long
Dim olApp As Object
Dim olMsg As Object
Dim arrEh As Variant
'Create Email Message
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then _
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)
With olMsg
.Display
If sSender <> "" Then
.SentOnBehalfOfName = sSender
End If
.To = sTo
.CC = sCCs
.HTMLBody = sHTML & .HTMLBody
.Subject = sSub
If Not IsMissing(sAttach) And Not IsNull(sAttach) Then
If Not IsArray(sAttach) Then
.Attachments.Add sAttach
GoTo Utah
End If
For lngLoop = LBound(sAttach) To UBound(sAttach)
.Attachments.Add sAttach(lngLoop)
Next lngLoop
Utah:
End If
If sAction = "Display" Then
.Display
ElseIf sAction = "Send" Then
.Send
End If
End With
On Error GoTo 0
'Clear Set Variables
Set olApp = Nothing
Set olMsg = Nothing
End Sub