创建一个包含对现有 Item 的引用的 Items 集合 [英] Create an `Items` collection containing references to already existing `Item`s

查看:82
本文介绍了创建一个包含对现有 Item 的引用的 Items 集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是创建一个 Items 集合,并向其中添加几个已经存在的 Item.例如,如果我有两个对 MailItem 的引用,我想设置一个包含这两个 ItemItems 集合.

I mean to create an Items collection, and add to it several already existing Items. For instance, if I have two references to MailItems, I want to set an Items collection containing those two Items.

应该是这样的

' ...
' Code that assigns references to olMail1 and olMail2, of type Outlook.MailItem
' ...
Dim MyItems As Outlook.Items
' Assign with Set / create the object
MyItems.Add olMail1
MyItems.Add olMail2

' Code that can use MyItems(1) to get a reference to olMail1

这怎么办?

需要澄清的是:

  1. 如何设置新集合.
  2. 如何添加项目.有关项目的文档.添加 似乎表明它用于添加新创建的对象,而不是对现有项目的引用.
  1. How to setup the new collection.
  2. How to add items. Documentation on Items.Add seems to indicate that it is used for adding newly created objects, not references to existing Items.

例如,我稍后会遍历该集合.我也会应用 FindRestrict;这允许在比整个 Folder 小得多的集合上应用这些方法.

I would later iterate through that collection, for instance. I would also apply Find or Restrict; this allows for applying the methods on a much smaller collection than a whole Folder.

PS:我什至无法从以下位置获得 Items 集合Application.ActiveExplorer.Selection(即不需要创建集合并一一添加Item).这对初学者来说是件好事.

PS: I cannot get an Items collection even from Application.ActiveExplorer.Selection (i.e., without need for creating the collection and add Items one by one). This would be good for a starter.

背景

我的意思是要找出哪些 Item 的发件人与给定的字符串相匹配.可能使我的案例比基本案例"更复杂的方面是:

I mean to find what Items have a sender matching a given string. The aspects that perhaps make my case somewhat more complex than a "base case" are:

  1. 我的意思是只对选定的一组项目应用过滤器.例如,仅在收件箱索引中选择的 Item 上.
  2. 我想做部分匹配.此时我不需要正则表达式,甚至完全使用通配符*?.但至少部分匹配在 InStr 中.
  3. 我的意思是为最小单元指定一个特定的Function:针对单个条件测试一个Item.然后循环遍历所有目标 Item 和所有条件.
  1. I mean to apply the filter only on a selected group of items. E.g., only on the Items that are selected in the Inbox index.
  2. I want to do partial matching. At this point I do not need regular expressions, or even full use of wildcards *?. But at least partial matching as in InStr.
  3. I mean to have a specific Function for the minimal unit: testing one Item, for a single condition. Then loop through all target Items, and all conditions.

我构思了 3 个方法:

  1. 使用规则.
  2. 使用FilterRestrict.这些不接受通配符(原则上?).
  3. 手动"检查条件,使用InStr,例如
  1. Use Rules.
  2. Use Filter or Restrict. These do not accept wildcards (in principle?).
  3. "Manually" check conditions, with InStr, e.g.

对于一种或多种方法,上述每个方面都可能具有一定的复杂性.

Each of the aspects above may bear some complexity for one or more of the approaches.

此时,我正在探索方法 2.我有一个对单个 Item 的引用,并且我发现了如何应用具有匹配条件的 Filter(请参阅http://www.outlookcode.com/news.aspx?id=30 ,http://blogs.msdn.com/b/andrewdelin/archive/2005/05/11/416312.aspx ,以及 Outlook 中的 VBA 搜索).但是要应用 Filter,我需要一个 Items 集合,其中包含我的单个项目.

At this point, I was exploring approach 2. I have a reference to a single Item, and I found how to apply a Filter with a matching condition (see http://www.outlookcode.com/news.aspx?id=30 , http://blogs.msdn.com/b/andrewdelin/archive/2005/05/11/416312.aspx , and the non-accepted answer of VBA Search in Outlook). But to apply the Filter, I need an Items collection, containing my single item.

我有一些使用方法 3 的方法(如 VBA 在 Outlook 中搜索的已接受答案中所建议的)a>).

I have something working with approach 3 (as suggested in the accepted answer of VBA Search in Outlook).

相关链接

识别满足规则的邮件项

推荐答案

我建议从 Outlook 2010 中的 VBA 入门 MSDN 中的文章.

I'd suggest starting from the Getting Started with VBA in Outlook 2010 article in MSDN.

无法在代码中创建 Items 类的实例.它是关联的,属于任何文件夹.您可以创建一个文件夹来获取新的 Items 实例.

An instance of the Items class can't be created in the code. It is asociated and belongs to any folder. You can create a folder to get a new Items instance.

您可以使用复制 Outlook 项目的方法来创建对象的另一个实例.然后Move方法可以用于将项目移动到另一个项目集合(文件夹).

You can use the Copy method of Outlook items to create another instance of the object. Then the Move method can be used to move the item to another Items collection (folder).

1.我的意思是只对选定的一组项目应用过滤器.例如,仅在收件箱索引中选择的项目上.

1.I mean to apply the filter only on a selected group of items. E.g., only on the Items that are selected in the Inbox index.

您需要迭代所有选定的项目.Find/FindNext 和 Restrict 方法仅属于 Items 类.因此,您只能将它们应用于文件夹项目.

You need to iterate over all selected items instead. The Find/FindNext and Restrict methods belong to the Items class only. So, you can apply them to the Folder items only.

2.我想做部分匹配.此时我不需要正则表达式,甚至完全使用通配符*?.但至少像 InStr 中的部分匹配.

2.I want to do partial matching. At this point I do not need regular expressions, or even full use of wildcards *?. But at least partial matching as in InStr.

请参阅使用字符串比较过滤项目.您可以使用 ci_startswithci_phrasematch 运算符.

See Filtering Items Using a String Comparison. You can use the ci_startswith or ci_phrasematch operators.

3.我的意思是为最小单元有一个特定的功能:针对单个条件测试一个项目.然后循环遍历所有目标项和所有条件.

3.I mean to have a specific Function for the minimal unit: testing one Item, for a single condition. Then loop through all target Items, and all conditions.

查看 MSDN 中的过滤项目部分它描述了在 Outlook 中的各种对象支持的筛选器中指定属性的一般规则.

Take a look at the Filtering Items section in MSDN which describes the general rules for specifying properties in filters that are supported by various objects in Outlook.

View 类的 Filter 方法应用于仅 Outlook 视图.Items 属性将返回项目的完整列表.

The Filter method of the View class is applied to the Outlook view only. The Items property will return the full list of items.

如果你指定最终目标会更好,而不是解决我们不清楚的问题的可能方法.

It would be better if you specify the final goal, not possible way to solve the problem which is not clear for us.

这篇关于创建一个包含对现有 Item 的引用的 Items 集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆