【发布时间】:2020-07-13 15:41:51
【问题描述】:
我已成功编写代码以在 Outlook 中创建任务。我在 Private Sub OutlookTask_Click() 中使用了下面的代码来定义收件人,它也运行良好。但是,我需要在 Outlook 任务表单中添加一些自定义字段。我将代码更改为 Private Sub test1_Click() 中列出的代码。使用 .save 将任务分配给我自己可以正常工作。当我分配给其他人时,我收到错误 Outlook 找不到名称。发布的答案很好,只需将 MyItem 更改为 OlTask。
Private Sub OutlookTask_Click()
Dim OlApp As Outlook.Application
Dim OlTask As Outlook.TaskItem
Dim OlTaskProp As Outlook.UserProperty
Dim OlLocation As Object
Dim OlDelegate As Outlook.Recipient
Dim TName As String
Set OlApp = CreateObject("Outlook.Application")
Set OlTask = OlApp.CreateItem(olTaskItem)
Set OlTaskProp = OlLocation.UserProperties.Find("Mlocation")
TName = Me.Alias
'Set OlDelegate = OlTask.Recipients.Add(TName)
With OLTask
.Subject = Me.Item
.StartDate = Me.Start_Date
.DueDate = Me.Due_Date
.Status = TStatus
.Importance = TPriority
.ReminderSet = True
.ReminderTime = Me.Due_Date - 3 & " 8:00AM"
.Body = Me.Description
.UserProperties("MLocation") = Me.Location
If Me.Alias = "Troy" Then
.Save
Else
.Assign
Dim myDelegate As Outlook.Recipient
Set myDelegate = OlTask.Recipients.Add(TName)
myDelegate.Resolve
End If
If myDelegate.Resolved Then
.Send
Else
MsgBox "Name not Found"
End If
MsgBox "Task Successful"
End Sub
Private Sub test1_Click()
Dim OlApp As Outlook.Application
Dim objFolder As MAPIFolder
Dim OLTask As Outlook.TaskItem
Dim OlItems As Outlook.Items
Dim OlDelegate As Outlook.Recipient
Dim TName As String
Dim TStatus As Integer
Dim TPriority As Integer
Set OlApp = CreateObject("Outlook.Application")
Set objFolder = OlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks)
Set OlItems = objFolder.Items
Set OLTask = OlItems.Add("IPM.Task.TroyTask")
TName = Me.Alias
Set OlDelegate = OLTask.Recipients.Add(TName)
With OLTask
.Subject = Me.Item
.StartDate = Me.Start_Date
.DueDate = Me.Due_Date
.Status = TStatus
.Importance = TPriority
.ReminderSet = True
.ReminderTime = Me.Due_Date - 3 & " 8:00AM"
.Body = Me.Description
.UserProperties("MLocation") = Me.Location
If Me.Alias = "Troy" Then
.Save
Else
.Assign
.Send
End If
End With
MsgBox "Task Successful"
End Sub
【问题讨论】: