Capture time mail was sent

▼魔方 西西 提交于 2019-12-11 05:46:17

问题


I am new to the Outlook Object Library. 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 but probably I have a wrong understanding of that.


回答1:


For all who are interested in this problem, find the progression on the solution: EXCEL VBA, Manual Outlook email sender, Class module Issue



来源:https://stackoverflow.com/questions/43682065/capture-time-mail-was-sent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!