在Outlook 2010中,“待办事项列表”包含所有任务项以及已标记的所有邮件项。为了计划每个待办事项需要多长时间,我在此视图中添加了内置的Outlook字段“Total Work”(使用Field Chooser)。
我手动更新“待办事项列表”视图中的“总工时”字段,我认为每个待办事项需要多长时间。
我想总计我的所有任务需要多少分钟。我试图在VBA中这样做。我可以从To-Do获取olTodo.TotalWork,其中olTodo.Class = olTask,但不是olTodo.Class = olMail。
我得到的错误消息是:运行时错误'438':对象不支持此属性或方法
据我所知,这条消息告诉我当oltodo.Class = olMail时olTodo不支持TotalWork属性,但是,我知道Outlook有TotalWork数据,因为我可以查看和更新所有项目的TotalWork(包括olMail项目) )从Outlook中的“待办事项列表”视图。
所以,我的问题是:如何以编程方式从VBA访问该数据?
这是我的代码:
Sub CountMinutesNeeded()
Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim olTodo As Object
Dim iMinuteCount As Long ' Minutes needed to complete to-do's
Dim olItms As Outlook.Items
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderToDo)
Set olItms = Fldr.Items
For Each olTodo In olItms
If olTodo.Class = olTask Then
' Only look at uncompleted tasks with a due date <= today OR Null
If (olTodo.DueDate <= Date Or olTodo.DueDate = #1/1/4501#) And olTodo.Complete = False Then
iMinuteCount = iMinuteCount + olTodo.TotalWork
End If
Else
If olTodo.Class = olMail Then
' Only interested in uncompleted items due today or earlier, or without due date
If (olTodo.TaskDueDate <= Date Or olTodo.TaskDueDate = #1/1/4501#) And olTodo.TaskCompletedDate = "1/1/4501" Then
' !!! This code does not work. I am unable to access olTodo.TotalWork when olTodo.class = olMail,
' Run-time error '438': Object doesn't support this property or method
'iMinuteCount = iMinuteCount + olTodo.TotalWork
' Instead, we'll assume 15 minutes
iMinuteCount = iMinuteCount + 15
End If
End If
End If
Next olTodo
MsgBox "Total Minutes Needed = " & iMinuteCount
End Sub
答案 0 :(得分:1)
您可以使用MailItem.PropertyAccessor.GetProperty访问该属性。使用OutlookSpy(单击IMessage按钮)确定DASL属性名称。