I am trying to find an email, by subject starting with specific text, to then download an attachment from that email.
I am using a variable with Restrict function,
The string comparison that DASL filters support includes equivalence, prefix, phrase, and substring matching.
For Each oOlItm In oOlInb.Items.Restrict("[Subject] = Findvariable")
It looks like you are searching for the exact match. But what you need is to find a substring using the following syntax:
criteria = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '%question%'"
Note that when you filter on the Subject property, prefixes such as "RE: " and "FW: " are ignored.
See Filtering Items Using a String Comparison for more information.
P.S. The Restrict method is an alternative to using the Find method or FindNext method to iterate over specific items within a collection. The Find or FindNext methods are faster than filtering if there are a small number of items. The Restrict method is significantly faster if there is a large number of items in the collection, especially if only a few items in a large collection are expected to be found.