I have an Excel workbook that contains a list of email templates and attachments.
I have an insert button for each list item to separately combine each email (required as per procedure).
I have written the code to combine them and display an email:
Public Sub SendToThisPerson()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim r, c As Integer
Dim b As Object
Set b = ActiveSheet.Buttons(Application.Caller)
With b.TopLeftCell
r = .Row
c = .Column
End With
r = 14
c = 3
Dim filename As String, subject1 As String, path1, path2, wb As String
Dim wbk As Workbook
filename = ThisWorkbook.Worksheets(1).Cells(r, c + 4)
path1 = Application.ThisWorkbook.Path & ThisWorkbook.Worksheets(1).Range("F4")
path2 = Application.ThisWorkbook.Path & ThisWorkbook.Worksheets(1).Range("F6")
wb = ThisWorkbook.Worksheets(1).Cells(r, c + 7)
Dim outApp As Outlook.Application
Dim oMail As Outlook.MailItem
Set outApp = New Outlook.Application
Set oMail = outApp.CreateItemFromTemplate(path1 & filename)
oMail.Display
subject1 = oMail.subject
subject1 = Left(subject1, Len(subject1) - 10) & Format(ThisWorkbook.Worksheets(1).Range("D7"), "DD/MM/YYYY")
Set wbk = Workbooks.Open(filename:=path2 & wb)
wbk.Worksheets(1).Range("I4") = ThisWorkbook.Worksheets(1).Range("D7").Value
wbk.Close True
With oMail
.subject = subject1
.Attachments.Add (path2 & wb)
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
The user decides either to send or not to send.
I would like to catch if the "Send" button was clicked, add the time of the send to the worksheet.
I experimented with Application events.