限制自定义属性在Outlook日历项目中不起作用

时间:2019-02-16 00:37:33

标签: vba outlook outlook-vba jet custom-properties

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

我知道我可以收集日历上所有项目的集合,然后循环遍历每个项目以找到我想要的东西-但这是我目前使用的方法,而且它很慢。

我查看了数十个站点,并找到了关于是否可行的相互矛盾的答案-但Microsoft似乎认为它(请参见第一个链接)以及其他人(请参见第二个链接)。

我在调试模式下使用了locals窗口,并且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过滤自定义属性上的当前视图,但是使用限制中的内容也不起作用。

0 个答案:

没有答案