2015-03-13 62 views
0

我需要從共享收件箱創建Outlook任務。到目前爲止,當下面的代碼運行,任務創建與共享收件箱的所有者,因爲我想,但保存時,我得到「您必須在公共文件夾中更改任務的所有者字段」錯誤,所有者將更改回給我。從共享收件箱創建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 "[email protected]" 'workaround to assign task for another owner, but does not show .BCC so not suitable solution. 
     .Owner = "[email protected]" ' 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 

回答

0

而不是使用Application.CreateItem的,叫Application.Session.CreateRecipient傳遞的名稱或郵箱的所有者的地址,叫Application.Session.GetSharedDefaultFolder,然後使用MAPIFolder.Items.Add

UPDATE

Set OlApp = CreateObject("Outlook.Application") 
set NS = olApp.getNamespace("MAPI") 
NS.Logon 
ste Recip = NS.CreateRecipient("[email protected]") 
set SharedFolder = NS.GetSharedDefaultFolder(Recip, olFoldersTasks) 
Set OlTask = SharedFolder.Items.Add 
... 
+0

嗨德米特里。我在vba方面經驗不足。你認爲你可以給你的建議一段代碼適配器嗎?當我試圖做到這一點,我只是不能讓它工作。感謝您的回答 – Trm 2015-03-13 19:01:05

+0

查看最新的答案。 – 2015-03-13 19:29:19

+0

嗨。我今天早上嘗試運行代碼,但無法使其工作。它運行,但不會產生任何任務。你有什麼想法可能是錯誤的? – Trm 2015-03-16 07:44:20

0

我設法得到下面的代碼工作。我相信最大的問題是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 "[email protected]" 
     '.Owner = "[email protected]" ' 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 
0

我認爲,我有更多的東西簡單此:

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([email protected])上返回共享的收件箱地址。