【问题标题】:Send email when Task is Completed - New approach任务完成时发送电子邮件 - 新方法
【发布时间】:2020-04-16 03:55:01
【问题描述】:

我正在使用下面的脚本将电子邮件自动转换为任务:

Sub ConvertMailtoTask(Item As Outlook.MailItem)
    Dim objTask As Outlook.TaskItem
    Set objTask = Application.CreateItem(olTaskItem)
With objTask
    .Subject = Item.Subject
    .StartDate = Item.ReceivedTime
    .Body = Item.Body
    .Companies = Item.SenderEmailAddress
    .Save
End With
    Set objTask = Nothing
End Sub

我还想在每次任务完成时自动向收件人发送一封电子邮件,而无需分配任务。我尝试了下面的方法,但没有返回任何内容。任何想法为什么?

Sub Item_PropertyChange(ByVal Name)
    Set oMsg = Application.CreateItem(olMailItem)
    If Item.Status = 2 Then
        With oMsg
            .To = "myemailaddress"
            .Subject = "Task Completed"
            .Body = Item.Subject
            .Send
        End With
    End If
End Sub

【问题讨论】:

    标签: vba outlook task


    【解决方案1】:

    触发事件需要这样的设置:

    在这个 Outlook 会话中

    Option Explicit ' Consider this mandatory
    ' Tools | Options | Editor tab
    ' Require Variable Declaration
    
    Dim WithEvents myInspector As Inspectors
    Dim WithEvents myTaskItem As TaskItem
    
    Private Sub Application_Startup()
        Set myInspector = Inspectors
    End Sub
    
    Private Sub myInspector_NewInspector(ByVal Inspector As Inspector)
        If TypeOf Inspector.CurrentItem Is TaskItem Then
            Set myTaskItem = Inspector.CurrentItem
        End If
    End Sub
    
    Private Sub myTaskItem_PropertyChange(ByVal Name As String)
    
        ' More than one property may change simultaneously
        Debug.Print Name
    
        If Name = "Status" Then
    
            'Status 2: completed
            Debug.Print Name & " has changed to: "
            Debug.Print " " & myTaskItem.Status
    
            If myTaskItem.Status = 2 Then
    
                ' a) The last task opened remains in memory until another task is opened.
                '    A selected task marked complete by menu or ribbon button will not trigger code,
                '     unless it was the last task opened.
                '    Selected items are automatically saved. The usual case.
                '
                ' b) Users may mark completed by accident.
                '
                ' c) If in an inspector window, the change has not yet been saved.
    
                MsgBox "Status of the last task that was opened now marked Completed." & vbCr & _
                   "If in an inspector window, the change has not yet been saved."
    
            End If
    
        End If
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-15
      相关资源
      最近更新 更多