【问题标题】:Create outlook task from shared inbox从共享收件箱创建 Outlook 任务
【发布时间】:2016-03-29 13:58:35
【问题描述】:

我需要从共享收件箱创建 Outlook 任务。到目前为止,当下面的代码运行时,任务是根据我的需要使用共享收件箱的所有者创建的,但是保存时我得到“您必须在公用文件夹中才能更改任务的所有者字段”错误并且所有者被改回给我。

我找不到解决方案,或者可能超出了我的理解范围。我很感激帮助。谢谢!

If task = "YES" Then
   user_task = "GR"
   Const olTaskItem = 3
   Dim OlApp As Object
   Dim OlTask As Object

   Set OlApp = CreateObject("Outlook.Application")
   Set OlTask = OlApp.CreateItem(olTaskItem)

   With OlTask
       '.Assign
       '.Recipients.Add "shared@inbox.com" 'workaround to assign task for another owner, but does not show .BCC so not suitable solution.
       .Owner = "shared@inbox.com" ' does not work. changes back to my user
       .Subject = material_full_email & " spp "
       .StartDate = Date
       .DueDate = Date + 7
       .Status = 1                 '0=not started, 1=in progress, 2=complete, 3=waiting,
                                   '4=deferred
       .Importance = 1             '0=low, 1=normal, 2=high
       .ReminderSet = False
       '.ReminderTime = dtReminderDate
       '.Categories = "Business" 'use any of the predefined Categorys or create your own
       .Body = Date & " " & user_task & ":" & " RFQ sent: " & Supplier1 & " / " & Supplier2 & " / " & Supplier3 & " / " & Supplier4
       '.Save   'use .Display if you wish the user to see the task form and make
       .Display       'them perform the save
   End With
End If

【问题讨论】:

    标签: vba outlook task


    【解决方案1】:

    不要使用Application.CreateItem,而是调用Application.Session.CreateRecipient,传递邮箱所有者的姓名或地址,调用Application.Session.GetSharedDefaultFolder,然后使用MAPIFolder.Items.Add

    更新

    Set OlApp = CreateObject("Outlook.Application")
    set NS = olApp.getNamespace("MAPI")
    NS.Logon
    ste Recip = NS.CreateRecipient("someuser@company.demo")
    set SharedFolder = NS.GetSharedDefaultFolder(Recip, olFoldersTasks)
    Set OlTask = SharedFolder.Items.Add
    ...
    

    【讨论】:

    • 嗨,德米特里。我在vba方面没有那么经验。你认为你可以给你的建议一个代码adapter的sn-p吗?当我尝试这样做时,我就是无法让它发挥作用。谢谢你的回答
    • 嗨。我今天早上尝试运行代码,但无法使其工作。它运行,但不生成任何任务。您知道可能出了什么问题吗?
    • 我确实解决了收件箱问题,但是我无法创建一个血腥的任务来挽救我的生命 :(。阅读无数主题,这些主题似乎都提供相同的建议,但无法使其发挥作用不知道为什么。
    • 我搞定了。我将您的评论标记为答案,因为它让我走上了正确的轨道
    【解决方案2】:

    我设法完成了以下代码工作。我认为最大的问题是 MS Outlook 库没有在参考文献中打勾。

    If task = "YES" Then
       user_task = "GR"
       Const olTaskItem = 3
       Dim olApp As Object
       Dim ns As Object
       Dim OlTask As Object
       Dim SharedFolder As Object
       Set olApp = CreateObject("Outlook.Application")
       Set ns = olApp.GetNamespace("MAPI")
       ns.Logon
       Set Recip = ns.CreateRecipient("inboxname")
       Set SharedFolder = ns.GetSharedDefaultFolder(Recip, olFolderTasks)
       Set OlTask = SharedFolder.Items.Add("IPM.Task")
       'Set OLApp = CreateObject("Outlook.Application")
       'Set OlTask = OLApp.CreateItem(olTaskItem)
    
       With OlTask
           '.Assign
           '.Recipients.Add "shared@inbox.com"
           '.Owner = "shared@inbox.com" ' not needed
           .Subject = material_full_email & " spp "
           .StartDate = Date
           .DueDate = Date + 7
           .Status = 1                 '0=not started, 1=in progress, 2=complete, 3=waiting,
                                       '4=deferred
           .Importance = 1             '0=low, 1=normal, 2=high
           .ReminderSet = False
           '.ReminderTime = dtReminderDate
           '.Categories = "Business" 'use any of the predefined Categorys or create your own
           .Body = Date & " " & user_task & ":" & " RFQ sent to suppliers: " & Supplier1 & " / " & Supplier2 & " / " & Supplier3 & " / " & Supplier4
           '.Save   'use .Display if you wish the user to see the task form and make
           .Display       'them perform the save
       End With
    End If
    

    【讨论】:

      【解决方案3】:

      我认为我有更简单的方法:

      Dim objOLApp As Outlook.Application
      Dim NewTask As Outlook.TaskItem
      ' Set the Application object
      Set objOLApp = New Outlook.Application
      Set NewTask = objOLApp.Session.Folders.Item(x).Items.Add(olTaskItem)
      With NewTask...
      

      其中“x”代表您的共享收件箱 ID(对我来说是 5)。您可以使用MsgBox Prompt:=objOLApp.Session.Folders.Item(x) 进行检查。它应该以正确的 ID (adress@server.com) 返回共享收件箱地址。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-28
        • 2015-08-31
        • 1970-01-01
        • 2017-10-03
        • 2018-08-18
        • 2017-03-15
        • 2019-01-26
        相关资源
        最近更新 更多