【问题标题】:Auto send reply when an email is marked complete in outlook当电子邮件在 Outlook 中标记为完成时自动发送回复
【发布时间】:2020-06-10 13:07:24
【问题描述】:

使用 Outlook,如果电子邮件包含我要做的工作,我会对其进行标记。当我完成工作时,我将电子邮件标记为完成(通过将标志更改为勾号)。我想自动发送一个回复,告诉最初的发件人工作已经完成。

我发现下面的代码似乎可以完成我想要的一半,但我希望它使用发件人的电子邮件地址而不是“John Smith”,并且最好包含初始电子邮件,就像我发送回复一样。

Public WithEvents olItems As Outlook.Items

Private Sub Application_Startup()
    Set olItems = Session.GetDefaultFolder(olFolderTasks).Items
End Sub

Private Sub olItems_ItemChange(ByVal Item As Object)
    Dim obApp As Outlook.Application
    Dim olMail As Outlook.MailItem
    Dim Recip As String

    'Replace "test" as per your needs
    If InStr(LCase(Item.Subject), "test") > 0 And Item.Complete = True Then
       'Replace with your desired contact
       Recip = "John Smith"
       If MsgBox("Do you want to send a report to " & Recip & " ?", vbYesNo + vbQuestion, "Confirm Sending Report") = vbYes Then
          Set obApp = Outlook.Application
          Set olMail = obApp.CreateItem(olMailItem)
          With olMail
               .To = Recip
               .Subject = "Complete: " & Item.Subject
               .Body = "Dear Mr. Smith" & vbCrLf & "I've completed this task in " & DateDiff("d", Item.CreationTime, Now) & " day" & Chr(40) & "s" & Chr(41) & "." & vbCrLf & vbCrLf & "Task Name: " & Item.Subject & vbCrLf & "Start Date: " & Item.StartDate & vbCrLf & "Due Date: " & Item.DueDate & vbCrLf & "Creation Time: " & Item.CreationTime & vbCrLf & "Completed Time: " & Now & vbCrLf & vbCrLf & "Task Details: " & vbCrLf & Item.Body
               .ReadReceiptRequested = True
               'To directly send it,use ".Send" instead
               .Display
          End With
       End If
    End If
End Sub

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    而不是在代码中创建一个新的邮件项:

    Set olMail = obApp.CreateItem(olMailItem)
    

    您可以只回复现有的,保留邮件正文和收件人:

    Set olMail = Item.Reply()
    

    请注意,您还可以使用 MailItem.ReplyAll 方法从原始邮件中创建对所有原始收件人的回复。

    Public WithEvents olItems As Outlook.Items
    
    Private Sub Application_Startup()
        Set olItems = Session.GetDefaultFolder(olFolderTasks).Items
    End Sub
    
    Private Sub olItems_ItemChange(ByVal Item As Object)
        Dim obApp As Outlook.Application
        Dim olMail As Outlook.MailItem
        Dim Recip As String
    
        'Replace "test" as per your needs
        If InStr(LCase(Item.Subject), "test") > 0 And Item.Complete = True Then
           'Replace with your desired contact
           Recip = "John Smith"
           If MsgBox("Do you want to send a report to " & Recip & " ?", vbYesNo + vbQuestion, "Confirm Sending Report") = vbYes Then          
              Set olMail = Item.Reply
              With olMail
                   .Subject = "Complete: " & Item.Subject
                   .Body = "Dear Mr. Smith" & vbCrLf & "I've completed this task in " & DateDiff("d", Item.CreationTime, Now) & " day" & Chr(40) & "s" & Chr(41) & "." & vbCrLf & vbCrLf & "Task Name: " & Item.Subject & vbCrLf & "Start Date: " & Item.StartDate & vbCrLf & "Due Date: " & Item.DueDate & vbCrLf & "Creation Time: " & Item.CreationTime & vbCrLf & "Completed Time: " & Now & vbCrLf & vbCrLf & "Task Details: " & vbCrLf & Item.Body
                   .ReadReceiptRequested = True
                   'To directly send it,use ".Send" instead
                   .Display
              End With
           End If
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2013-11-25
      • 2020-08-06
      • 2020-09-21
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多