0

我想向我的日历项目添加一个自定义属性(理想情况下它将包含一个唯一 ID),以便我可以使用 Restrict 来收集定期约会项目的实例。但是,虽然我似乎能够添加该属性,但我找不到任何方法来使用 Items.Restrict() 方法来查找包含该属性的项目。

我知道我可以获取日历上所有项目的集合并循环每个项目以找到我想要的 - 但这是我当前使用的方法,而且速度很慢。

我查看了几十个站点,发现关于这是否可能的相互矛盾的答案 - 但微软似乎认为它是(见第一个链接),以及其他人(见第二个链接)。

我在调试模式下使用了本地窗口,并且 Restrict 绝对没有收集任何对象。

我只能假设我在列部分做错了(基于此“必须在应用过滤器的文件夹中定义自定义属性。如果自定义属性仅在项目中定义,则搜索将失败“ - 第一个链接)或视图,但我不知道是什么。

我知道我不能使用 TableView 因为它不包含重复实例(请参阅第三个链接)。

  1. https://docs.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/filtering-a-custom-field
  2. http://www.outlookcode.com/threads.aspx?forumid=2&messageid=27942
  3. https://docs.microsoft.com/en-us/office/client-developer/outlook/pia/how-to-filter-recurring-appointments-and-search-for-a-string-in-the-subject

    Sub AddAndRestrictCustomProperty()
    
    Dim NS As Outlook.NameSpace
    Dim dcal As Folder
    Dim dCalItmes As Items
    Dim objd As Items, objc As Items
    Dim item As Outlook.AppointmentItem
    Dim upCheck As Outlook.UserProperty
    Dim udpCheck As Outlook.UserDefinedProperty
    
    Set NS = Application.GetNamespace("MAPI")
    Set dcal = NS.GetDefaultFolder(olFolderCalendar)
    Set dCalItems = dcal.Items
    
    Set item = dCalItems.Add(olAppointmentItem)
    With item
        .Subject = "Placeholder Appt"
        .Start = "2/12/2019 4:30PM"
        .Body = "nothing"
        .MeetingStatus = olMeeting
        .Save
    End With
    
    'adds custom property
    Set upCheck = item.UserProperties.Add("userPropCheck", olText, True, olText)
    upCheck.Value = "testing"
    Debug.Print item.ItemProperties.item("userPropCheck").Value 'prints "testing"
    item.Save
    
    'gets instances of custom property in objd
    dCalItems.Sort "[Start]"
    dCalItems.IncludeRecurrences = True
    Set objd = dCalItems.Restrict("[subject] = Placeholder Appt And [Start] >= '2/11/2019' and [Start] <= '2/13/2019'")
    Debug.Print objd(1).ItemProperties.item("userPropCheck").Value 'prints testing
    
    'setColumns seems to not work for custom properties
    objd.SetColumns ("userPropCheck, subject, start") 'ERROR: The property "userPropCheck" is unknown error
    
    'Jet Restrict Fails
    Set objc = dCalItems.Restrict("[userPropCheck] = " & Chr(34) & "testing" & Chr(34))
    Debug.Print objc(1).ItemProperties.item("userPropCheck").Value 'ERROR: object variable or with block variable not set error
    
    'Jet Find Fails
    Set objc = dCalItems.Find("[userPropCheck] = " & Chr(34) & "testing" & Chr(34))
    Debug.Print objc(1).ItemProperties.item("userPropCheck").Value 'ERROR: object variable or with block variable not set error
    
    'DSAL Restrict Fails
    sFilter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/userPropCheck" & Chr(34) & "= 'testing'" ''"@SQL=" & Chr$(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/userPropCheck" & Chr(34) & " = 'testing'"
    Set objc = dCalItems.Restrict(sFilter)
    Debug.Print objc(1).ItemProperties.item("userPropCheck").Value 'ERROR: object variable or with block variable not set error
    
    'DSAL Find Fails
    sFilter = "@SQL=" & Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/userPropCheck" & Chr(34) & "= 'testing'" ''"@SQL=" & Chr$(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/userPropCheck" & Chr(34) & " = 'testing'"
    Set objc = dCalItems.Find(sFilter)
    Debug.Print objc(1).ItemProperties.item("userPropCheck").Value 'ERROR: object variable or with block variable not set error
    
    'THIS WORKS to filter the actual calendar view
    Set objView = Application.ActiveExplorer.CurrentView
    objView.Filter = Chr(34) & "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/userPropCheck" & Chr(34) & "= 'testing'"
    objView.Save
    objView.Apply
    
    End Sub
    

如您所见,我迷路了。我可以向项目添加自定义属性,然后限制该属性以外的其他内容以获取项目,然后打印出自定义属性,我可以使用 DSAL view.Filter 过滤自定义属性上的当前视图,但使用在限制中也不起作用。

4

0 回答 0