【发布时间】:2018-06-13 15:57:31
【问题描述】:
有没有办法在发送电子邮件后设置提醒?
我有创建电子邮件和设置提醒的 VBA 代码。
Sub RendaFixaAplicação()
Dim texto As String
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
texto = Range("J2").Value & ",insert some text here"
With OutMail
.Display
.to = Range("J3").Value
.CC = Range("J4").Value
.Subject = "Insert a subject here " & Range("E2").Value
.HTMLBody = texto & .HTMLBody
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Call alerta1
End Sub
在代码末尾使用“Call alerta1”进行提醒,编程如下:
Sub alerta1()
Dim objOutlookApp As Outlook.Application
Dim objTask As Outlook.TaskItem
Dim hora As String
Dim wd As WorksheetFunction
Set wd = Application.WorksheetFunction
Dim diautil As Date
diautil = wd.WorkDay(Date, 1)
If Time > "15:00:00" Then
hora = diautil & " 14:00:00"
Else
If Time < "14:00:00" Then
hora = Date & " 14:00:00"
Else
hora = Date & " 14:45:00"
End If
End If
Set objOutlookApp = CreateObject("Outlook.Application")
Set objTask = objOutlookApp.CreateItem(olTaskItem)
objTask.Subject = "Insert a Subject Here - " & Range("E2").Value
objTask.Display
objTask.body = "Cliente: " & Range("K2").Value & vbNewLine & "Email cliente: " & Range("J3").Value
objTask.ReminderSet = True
objTask.ReminderTime = hora
objTask.DueDate = hora
objTask.Close (olSave)
End Sub
它设置我是否发送电子邮件的提醒。
我不能在电子邮件中使用 .Send,因为需要在电子邮件中进行一些编辑。
有没有办法让 Excel 等待电子邮件发送然后运行“alerta1”?
【问题讨论】:
-
查看MailItem.Send 事件。然后,您可以将警报设置为仅在发送电子邮件时创建
-
您可以在 SentItems 文件夹 stackoverflow.com/questions/11263483/… 的 ItemAdd 事件中将提醒代码移动到 Outlook 中。我建议你可以设置一个特定的主题、文本、用户属性来指示要处理的电子邮件。您可以尝试像stackoverflow.com/questions/28610291/… 一样将所有代码保留在 Excel 中。