I'm creating a macro that pulls e-mail attachments into a folder to be opened and copied, which works 100% perfect when the subject name is predefined, i.e. never changes.
' this works
Set oOlInbFiltered = oOlInb.Items.Restrict("[Subject] = " & SubjectName)
However, when I try to instead restrict for a preset beginning, say every email begins with 'aaaaa', it causes an automation error with the code below:
' this doesnt
Set oOlInbFiltered = oOlInb.Items.Restrict("[Subject] like '" & PrefixName & "%'")
Any help?
Expected results: No error message, files in folder. Instead I receive
Run-time error '-2147352567 (800200009)': Automation error Exception Occurred.
Try to use the following code instead:
criteria = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '" & PrefixName & "%'"
Set oOlInbFiltered = oOlInb.Items.Restrict(criteria)