I mean to create an Items
collection, and add to it several already existing Item
s.
For instance, if I have two references to MailItem
s, I want to set an Items
collection containing those two Item
s.
It would be something like
' ...
' 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
How can that be done?
Things to clarify are:
- How to setup the new collection.
- 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.
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: I cannot get an Items
collection even from
Application.ActiveExplorer.Selection
(i.e., without need for creating the collection and add Item
s one by one). This would be good for a starter.
Background
I mean to find what Item
s have a sender matching a given string. The aspects that perhaps make my case somewhat more complex than a "base case" are:
- I mean to apply the filter only on a selected group of items. E.g., only on the
Item
s that are selected in the Inbox index. - 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
. - I mean to have a specific
Function
for the minimal unit: testing oneItem
, for a single condition. Then loop through all targetItem
s, and all conditions.
I conceived 3 approaches:
- Use
Rules
. - Use
Filter
orRestrict
. These do not accept wildcards (in principle?). - "Manually" check conditions, with
InStr
, e.g.
Each of the aspects above may bear some complexity for one or more of the approaches.
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.
I have something working with approach 3 (as suggested in the accepted answer of VBA Search in Outlook).
Related links