我正在制作一张Excel工作表,其中组长编写一个任务,然后将其发送给工作人员。
我已经弄清楚了这部分,但是每个任务都发送给三个人。工人,组长和他的助手。
有没有办法只向组长和助手发送有关任务的通知?
我研究了TaskItem属性,发现了两个可能的解决方案:
但是我不明白它们是如何工作的。有人可以解释他们的工作方式,还是有更好的解决方案来解决这个问题?
这就是我使用这两个属性的方式:
With objTask
.Assign
.Subject = Worksheets("Naloge").Range("E" & Trow)
.Body = "Some text"
.Status = olTaskNotStarted
.Importance = olImportanceHigh
.StartDate = Worksheets("Naloge").Range("B" & Trow)
.DueDate = Worksheets("Naloge").Range("C" & Trow)
.ReminderTime = .DueDate - 1.5
'.Owner = Worksheets("Naloge").Range("G" & Trow)
'.Role = Worksheets("Naloge").Range("G" & Trow)
.Recipients.Add (EmailTo)
If Len(EmailCc) > 1 Then
'.Recipients.Add (EmailCc)
.StatusUpdateRecipients (EmailCc)
.StatusOnCompletionRecipients (EmailCc)
End If
If Len(EmailVodja) > 1 Then
.StatusOnCompletionRecipients.Add (EmailVodja)
.StatusUpdateRecipients.Add (EmailVodja)
End If
.Send
.Save
End With
代码在这两个属性处停止并显示
编译错误:“无效使用属性”
答案 0 :(得分:1)
您必须在公用文件夹中生成一个任务,才能将其分配给另一个所有者。
要添加其他收件人,请添加新的Recipient
对象,然后定义其类型。类型olUpdate
导致StatusUpdateRecipients
,类型olFinalStatus
导致StatusOnCompletionRecipients
。
Private Sub GeneratePublicTask()
Dim objNamespace As Outlook.NameSpace
Dim objPublicFolderRoot As Outlook.Folder
Dim objPublicTaskFolder As Outlook.Folder
Dim objMyTaskFolder As Outlook.Folder
Dim objTask As Outlook.TaskItem
Dim objRecipientOwner As Outlook.Recipient
Dim objRecipientEveryStatusUpdate As Outlook.Recipient
Dim objRecipientFinalStatusOnly As Outlook.Recipient
Dim EmailOwner As String
Dim EmailEveryStatusUpdate As String
Dim EmailFinalStatusOnly As String
EmailOwner = "IsOwner@ACME.com"
EmailEveryStatusUpdate = "GetsEveryUpdate@ACME.com"
EmailFinalStatusOnly = "GetsFinalStatusOnly@ACME.com"
Set objNamespace = Application.GetNamespace("MAPI")
Set objPublicFolderRoot = objNamespace.GetDefaultFolder(olPublicFoldersAllPublicFolders)
Set objPublicTaskFolder = objPublicFolderRoot.Folders("Public Tasks")
Set objTask = objPublicTaskFolder.Items.Add(olTaskItem)
' For local folder tests:
' Set objMyTaskFolder = objNamespace.GetDefaultFolder(olFolderTasks)
' Set objTask = objMyTaskFolder.Items.Add(olTaskItem)
With objTask
.Subject = "Example Subject Text"
.Body = "Example Body Text"
.Status = olTaskNotStarted
.Importance = olImportanceHigh
.StartDate = Date
.DueDate = Date + 7
.ReminderTime = .DueDate - 1.5
.Role = "Example Role Text"
Set objRecipientOwner = .Recipients.Add(EmailOwner)
'objRecipientOwner.Type = olTo ' not necessary, first is To
Set objRecipientEveryStatusUpdate = .Recipients.Add(EmailEveryStatusUpdate)
objRecipientEveryStatusUpdate.Type = olUpdate
Set objRecipientFinalStatusOnly = .Recipients.Add(EmailFinalStatusOnly)
objRecipientFinalStatusOnly.Type = olFinalStatus
.Recipients.ResolveAll
.Assign
'.Save
Debug.Print .Owner ' still yourself?
Debug.Print .Ownership ' 0 = olNewTask, 2 = olOwnTask, 1 = olDelegatedTask
Debug.Print .StatusUpdateRecipients ' Type olUpdate
Debug.Print .StatusOnCompletionRecipients ' Type olFinalStatus
.Display
'.Send
End With
End Sub