First of all, I d suggest using Instr
function instead of comparing strings. The Categories string may contain other markers, not only your single one.
不清楚用什么法典搜寻有特定类别组的物品,最可能的话,你只是对纸浆中所有不好的物品 it。 相反,你需要使用<代码>Find/FindNext
或Restrict
方法,只接收符合您条件的项目。 例如:
Sub MoveItems()
Dim myNamespace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myItems As Outlook.Items
Dim myRestrictItems As Outlook.Items
Dim myItem As Outlook.MailItem
Set myNamespace = Application.GetNamespace("MAPI")
Set myFolder = _
myNamespace.GetDefaultFolder(olFolderInbox)
Set myItems = myFolder.Items
Set myRestrictItems = myItems.Restrict("[Categories] = testword ")
do whatever you need with items found, for example, move to a subfolder
For i = myRestrictItems.Count To 1 Step -1
myRestrictItems(i).Move myFolder.Folders("Business")
Next
End Sub
<代码>Categories field is of category keywords, which is aiming to hold multi Value. 在从方案角度看,<代码>Categories field behaves as a Text
field, 并且脚步必须完全一致。 案文载体中的数值由 com和空间分开。 这通常意味着,如果含有一个以上价值的话,你不能使用<代码>Find和关于关键词的限制性
方法。 例如,如果您在商业类别中有一个联系,在企业和社会类别上有一个联系,那么你就无法轻易使用<代码>Find和Restrict
方法检索所有属于商业类别的项目。 相反,你可以通过文件夹中的所有接触,并使用<条码>。
可能的例外是,如果你将<代码>Categories field限制在两个或两个低数值上。 然后,可使用<代码>Find和>Restrict
方法,由OR的逻辑操作者检索所有物项。 例如(在假体编码中):“企业”或“企业、个人”或“个人”
注意<代码> 类别代码>指示对个案不敏感。
在以下条款中更多地了解这些方法:
也可找到。 方法有用。 使用<代码>先进Search的主要好处 展望的方法是:
- The search is performed in another thread. You don’t need to run another thread manually since the
AdvancedSearch
method runs it automatically in the background.
- Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The
Restrict
and Find
/FindNext
methods can be applied to a particular Items
collection (see the Items property of the Folder
class in Outlook).
- Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the
IsInstantSearchEnabled
property of the Store
class).
- You can stop the search process at any moment using the
Stop
method of the Search
class.