OutlookEX UDF - Find Items
Here you'll find detailed information on how to find items which then can be processed by further functions.
Function _OL_ItemFind
Finds items (contacts, appointments ...) in the specified folder (and - optional - any subfolder) and returns the requested properties of the found items in an array.
Parameters
The following parameters define what is searched for and what properties are returned by the function:
- $oOL
- Outlook object returned by a preceding call to _OL_Open()
- $vFolder
- Folder object as returned by _OL_FolderAccess or full name of folder where the search will be started. If you want to search a default folder you have to specify the folder object.
- $iObjectClass (Optional)
- Class of items to search for. Defined by the Outlook OlObjectClass enumeration (default = $olContact). Examples:
- $olAppointment - Represents an AppointmentItem object
- $olContact - Represents a ContactItem object
- $olMail - Represents a MailItem object
- $olTask - Represents a TaskItem object
- $sRestrict (Optional)
- Filter text to restrict number of items returned (exact match). Can be combined with $sSearchName/$sSearch. The filter can be a Jet query or a DASL query with the @SQL= prefix (which isn't described here).
- Jet query language syntax:
- Restrict filter: Filter LogicalOperator Filter ...
- LogicalOperator: And, Or, Not. Use ( and ) to change the processing order
- Filter: "[property] operator 'value'" or '[property] operator "value"'
- Operator: <, >, <=, >=, <>, =
- Example: "[Start]='2011-02-21 08:00' And [End]='2011-02-21 10:00' And [Subject]='Test'"
- See: http://msdn.microsoft.com/en-us/library/cc513841.aspx - "Searching Outlook Data" or http://msdn.microsoft.com/en-us/library/bb220369(v=office.12).aspx - "Items.Restrict Method"
- N.B.:
- Pass time as HH:MM, HH:MM:SS is invalid and returns no result.
- It seems that Outlook interprets the format of a passed date. 2020-04-01 will not be used as first of April but 4th of January. Pass the date as 01-04-2020 to make sure you get the desired result.
- Some properties can't be used in a filter (e.g. Body, Categories, HTMLBody) and will cause an error. Please check the "Items.Restrict Method" link above.
- $sSearchName (Optional)
- Specify the name of a single property to be searched for the value specified by $sSearchValue (partial match). Can be combined with $sRestrict.
- Be sure to specify the property in correct case e.g. "FirstName" is valid, "Firstname" is invalid.
- $sSearchValue (Optional)
- String value to search for. All items are returned where the string can be found at any position of the property e.g. if property "Subject" has the value of "This is a test" then the item will be found if $sSearchValue is "This" or "is a" or "test".
- $sReturnProperties (Optional)
- Comma separated list of properties to return (default = depending on $iObjectClass). Be sure to specify the properties in correct case e.g. "FirstName" is valid, "Firstname" is invalid.
- For pseudo properties please see the next section.
- $sSort (Optional)
- The name of the property by which to sort, which may be enclosed in brackets, for example, "[CompanyName]".
- User-defined properties that contain spaces must be enclosed in brackets. After the property the optional string "True" to sort descending (default = None) might follow.
- E.g. "[Subject], True" sorts the result descending on the subject.
- $iFlags (Optional)
- Flags to set different processing options. Can be a combination of the following:
- 1 - Subfolders will be included
- 2 - Row 1 contains column headings. Therefore the number of rows/columns in the table has to be calculated using UBound
- 4 - Just return the number of records. You don't get an array, just a single integer denoting the total number of records found
- $sWarningClick (Optional)
- The entire path (drive, directory, file name and extension) to 'OutlookWarning2.exe' or another exe with the same function (default = None)
Pseudo properties
Some properties can't be accessed by their name using parameter $sReturnProperties.
That's why the following pseudo properties have been implemented:
- @FolderObject - Object of the folder where the item resides. Helpful when searching subfolders.
- @ItemObject - Object of the item that matches the search criteria
You can access all available properties and methods of an item by using this two objects.
Issues
When the returned array holds references to an item (e.g. @FolderObject, @ItemObject) not all data might be returned. This could be caused by a limit the Exchange admin has set for the number of items you can open simultaneously.
You might get the following error message: Your server administrator has limited the number of items you can open simultaneously.
Details can be found here.