使用Outlook vbs更新分配给字段

时间:2013-12-04 19:43:51

标签: vba vbscript outlook

在Outlook中,我已在“任务”表单中创建自定义表单。我用它来为其他用户分配任务。现在我尝试在用户未填写分配到字段时添加一些代码(例如,如果任务是他在保存任务时检查它并询问他是否需要将自己添加为已分配的用户。我的问题是我可以如果它是空的,我不会更新分配的字段。我得到错误我的代码如下:

   Sub Item_Write(ByVal Name) 
      Set objPage = Item.GetInspector.ModifiedFormPages("Assign Task")
      Set objControl = objPage.Controls("RecipientControl1")
      Set objControl2 = objPage.Controls("Textbox1")
      Set objControl4 = objPage.Controls("Textbox4")

      Set oMsg = Application.CreateItem(olMailItem)
      Set objNS = oMsg.Session

     MyValue= objControl2.Value
     MyValue4= objControl4.Value

     if MyValue= "" then
     if Msgbox ("Task isn't assign to anybody. Do you want to assign yourself?", vbYesNo)=vbYes then 
 objControl.Value=objNS.CurrentUser.Name


 End if
 End if
End Sub

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案,

我将事件Item_Close和Outlook属性名称用于收件人控件,而不是Vbs中的控件名称。在下面查找我的代码,该代码在用户将任务分配给某人之前工作且形式不完整。

     Function Item_Close()
      Set objPage = Item.GetInspector.ModifiedFormPages("Assign Task")
      Set objControl = objPage.Controls("Textbox1")
      Set objNS = Application.GetNamespace("MAPI")
      Set objContro2 = objPage.Controls("Frame1")


      assigned=objControl.Value
      'Use always Outlook property names and not Control Properties(as RecipientControl in case)
       if assigned= "" then
        info =Msgbox ("The task is not assigned to a user. Do you want to assign yourself?", vbYesNo)
      Select Case info
       Case 6
        'Use always Outlook property names and not Control Properties(as RecipientControl in case)
     Set myAssignedTo = Item.Recipients.Add(objNS.CurrentUser.Name)
     Me.Save
      Case 7
         MsgBox "You must Assign Task to a user before save it.", vbExclamation

        Item_Close=False
        Item.GetInspector.SetCurrentFormPage "Assign Task"
   End Select
 End if
End Function