Business Contact Manager / Outlook 2013 / VBA - 任务状态未更新 [英] Business Contact Manager/Outlook 2013/VBA - Task status not updating

查看:69
本文介绍了Business Contact Manager / Outlook 2013 / VBA - 任务状态未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图略微修改此处显示的示例:

I am attempting to slightly modify the example shown here:

http://msdn.microsoft.com/en-us/library/office/bb268004(v = office.12).aspx

http://msdn.microsoft.com/en-us/library/office/bb268004(v=office.12).aspx

(更新商业项目状态时发送电子邮件的代码)。  我正在努力使其在更新Project TASK时发送电子邮件。  这是我得到的:

(code to send an email when a Business Project status is updated).  I'm trying to also make it so that an email is sent when a Project TASK is updated.  Here is what I've got:

' In ThisOutlookSession

Option Explicit
Dim WithEvents inspectors As inspectors
Dim WithEvents project As TaskItem
Dim root As Folder

Private Sub Application_Startup()
    Set inspectors = Application.inspectors
    Set root = Application.Session.Folders("Business Contact Manager")
    Set project = root.Folders("Business Records").Folders("Business Projects").Items(1)
End Sub
Private Sub inspectors_NewInspector(ByVal inspector As inspector)
    If inspector.CurrentItem.Class <> olTask Then Exit Sub
    Dim oTaskItem As TaskItem
    Set oTaskItem = inspector.CurrentItem
    If oTaskItem.MessageClass <> "IPM.Task.BCM.Project" And oTaskItem.MessageClass <> "IPM.Task.BCM.ProjectTask" Then Return
    Dim oProjectWrapper As New ProjectWrapper
    oProjectWrapper.Init inspector
End Sub


' In Class Module ProjectWrapper

Option Explicit
Dim WithEvents inspector As inspector
Dim WithEvents project As TaskItem
Dim self As ProjectWrapper
Dim originalProjectStatus As String

Public Sub Init(anInspector As inspector)
    Set self = Me
    Set inspector = anInspector
    Set project = inspector.CurrentItem
End Sub

Private Sub inspector_Close()
    Set self = Nothing
End Sub

Private Sub project_Open(Cancel As Boolean)
    If project.MessageClass = "IPM.Task.BCM.Project" Then
    originalProjectStatus = project.UserProperties.Item("Project Status").Value 'This line is the original
    ElseIf project.MessageClass = "IPM.Task.BCM.ProjectTask" Then
    originalProjectStatus = project.UserProperties.Item("ActivityStatus").Value
    End If
    MsgBox "Original: " & originalProjectStatus
End Sub

Private Sub project_Write(Cancel As Boolean)
    Dim projectStatus As String
    If project.MessageClass = "IPM.Task.BCM.Project" Then
    projectStatus = project.UserProperties.Item("Project Status").Value 'This line is the original
    ElseIf project.MessageClass = "IPM.Task.BCM.ProjectTask" Then
    projectStatus = project.UserProperties.Item("ActivityStatus").Value
    End If
    MsgBox "New: " & projectStatus

    If originalProjectStatus <> projectStatus Then
        originalProjectStatus = projectStatus
        Dim mail As MailItem
        Set mail = Application.CreateItem(olMailItem)
        mail.Subject = "Project Status changed"
        mail.Body = "Project """ + project.Subject + """ changed. New Project Status: " + projectStatus
        mail.To = "someone@example.com"
        mail.Send
    End If

End Sub

我添加了MsgBoxes以便我可以看到究竟是什么发送。  代码在Business Project状态更新时有效 - MsgBox在您第一次打开时显示原始状态,保存时显示新状态,并发送电子邮件。



但是使用Project Task ,MsgBox会在您打开Task时显示原始状态,即使您更改并保存任务后它仍然显示原始状态。  并且它不会发送电子邮件。  如果我在
结束时取出If语句(如果是originalProjectStatus<> projectStatus Then),它会发送电子邮件,但它会在更改之前发送原始任务状态。



因此,出于某种原因,似乎在实际保存任务时没有保存或注册任务状态。  我错过了一些明显的东西,还是我需要以不同的方式解决这个问题?  感谢您提供的任何帮助。

I added the MsgBoxes so that I could see what exactly was being sent.  The code works when a Business Project status is updated -- the MsgBox shows the original status when you first open it, the new status when you save it, and it sends the email.

But with the Project Task, the MsgBox shows the original status when you open the Task, and it still shows the original status even after you change it and save the task.  And it doesn't send the email.  If I take out the If statement at the end (If originalProjectStatus <> projectStatus Then), it does send the email then, but it sends it with the original Task status before it was changed.

So, for some reason, it seems like the Task status isn't getting saved or registered at the time the Task is actually saved.  Am I missing something obvious, or do I need to go about this a different way?  Thanks for any help you can provide.

推荐答案

您好,

我已将此主题移至 Outlook for Developers 论坛,因为您需要有关VBA编码的帮助。

I've moved this thread to Outlook for Developers forum since you need help with VBA coding.

我们推荐的原因如果发布得当,您将获得最合格的受访者群体,而定期阅读论坛的其他合作伙伴可以分享他们的知识或从您与我们的互动中学习。感谢您的理解。

问候,

Melon Chen

TechNet社区支持


这篇关于Business Contact Manager / Outlook 2013 / VBA - 任务状态未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆