Using your examples, basically you need two modules in your macro enabled workbook.
1. a class module renamed CMailItemEvents with the code as follows:
Class Module.jpg
Option Explicit
Public WithEvents itm As Outlook.MailItem
Private Sub itm_Close(Cancel As Boolean)
Dim blnSent As Boolean
On Error Resume Next
blnSent = itm.sent
If Err.Number = 0 Then
Debug.Print "not sent"
Else
' do what you need to do
End If
End Sub
2. an ordinary module, the name of which doesn't matter containing the following code:
Ordinary module.jpg
Option Explicit
Public itmevt As New CMailItemEvents
Public aOutlook As Outlook.Application
Public Sub SendISINRequestEmail(SendMailTo, CCAddresses, MailSubject, MailBody)
Dim aEmail As Outlook.MailItem
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
On Error Resume Next
Set aOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If aOutlook Is Nothing Then Set aOutlook = New Outlook.Application
Set aEmail = aOutlook.CreateItem(0)
Set itmevt.itm = aEmail
aEmail.Subject = MailSubject
aEmail.HTMLBody = MailBody
aEmail.SentOnBehalfOfName = "SH-SPVOPS@ubs.com"
aEmail.To = SendMailTo
aEmail.CC = CCAddresses
aEmail.Attachments.Add ("P:\Test Termsheet PDF.pdf")
aEmail.Display
End Sub
Finally you need to ensure that you have a reference to the Outlook object library checked in Tools > References
Object Library.jpg
Save the workbook and it should then work.