Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 创建Outlook.Items的空集合_Vba_Collections_Outlook - Fatal编程技术网

Vba 创建Outlook.Items的空集合

Vba 创建Outlook.Items的空集合,vba,collections,outlook,Vba,Collections,Outlook,我有一个vba宏代码,我在其中执行以下操作: Dim myFoundItems As Outlook.Items Set myFoundItems = myCalendars.Restrict("[customUserProperty] = '" & sId & "'") 其中customUserProperty是我在宏中添加的用户属性(该限制后的几行)。然而,在第一次运行这个宏时,我得到一个错误,即属性不存在。因此,我正在考虑设置将myFoundItems设置为空集合的错误处

我有一个vba宏代码,我在其中执行以下操作:

Dim myFoundItems As Outlook.Items
Set myFoundItems = myCalendars.Restrict("[customUserProperty] = '" & sId & "'")
其中customUserProperty是我在宏中添加的用户属性(该限制后的几行)。然而,在第一次运行这个宏时,我得到一个错误,即属性不存在。因此,我正在考虑设置将myFoundItems设置为空集合的错误处理程序。然而,我不能以任何方式实现这一点

我试过使用下面的代码,但它会导致另一个错误

Set myFoundItems = New Collection

也许您知道如何将myFoundItems设置为空集合,甚至知道如何更好地检查是否已创建UserProperty?

您不能使用new关键字创建新的Items实例。相反,您必须使用Folder类的Items属性

问题的原因是您不能仅使用筛选器查询中的名称来引用用户属性。相反,您必须使用如下DASL查询(VBA):

有关更多信息,请参阅。您也可能会发现该页面很有帮助

criteria = "@SQL=" _ 
  & Chr(34) & "http://schemas.microsoft.com/mapi/string/" _ 
  & "{00020329-0000-0000-C000-000000000046}/customUserProperty" & Chr(34) _ 
  & " = 'Microsoft'"