-
Outlook Rules Question
Hi, I am currently using InStr to look for a String in another String
Code:
findRefund = InStr(1, "Refund order - Item code 10000000", "Refund", vbTextCompare)
But what if I want to use multiple search criteria, with capitalization variants?
E.g.
Code:
Refund
refund
Exchange
exchange
Return
return
Writing separate InStr lines for each criteria seems inefficient.
How do you search for all of these criteria using minimal code?
-
Code:
Dim Criteria
Criteria = Array("refund", "exchange", "return") '<--- all lowercase
Dim SearchedString as ??? Range? Array? String? Depends on Data Structure
SearchedString = ???
For i = Lbound(Criteria) To Ubound(Criteria)
Refund = Instr(LCase(SearchedString), Criteria(i))
If Refund then Exit For
Next
Possible usage
Code:
For Each Cel in Range("B:B")
If RefundDue(Cel) then cel.Offset(, 1) = "Refund this Item"
Next
End...
Function RefundDue(SearchedString As Variant) As Boolean
Const Criteria = Array("refund", "exchange", "return")
For i = Lbound(Criteria) To Ubound(Criteria)
RefundDue = Instr(LCase(SearchedString), Criteria(i))
If RefundDue then Exit For
Next
End Function
-
Outlook Rules Question
Hi, is it possible to specify a rule where Outlook scans all the attachment file names to see if any of them contain any from a list of substrings? Case insensitive.
E.g. any attachment file name contains: refund, Refund, exchange, Exchange, return, Return
I want to avoid doing this via VBA where possible
If not, please provide sample VBA code. Thanks
-
You would need a rule with a script to check the incoming mail items e.g.
Code:
Sub CheckAttachments(Item As Outlook.MailItem)
Dim vCriteria As Variant
Dim olAtt As Attachment
Dim i As Integer
vCriteria = Array("refund", "exchange", "return") '<--- all lowercase
If TypeName(Item) = "MailItem" Then
If Item.Attachments.Count > 0 Then
For Each olAtt In Item.Attachments
For i = 0 To UBound(vCriteria)
If InStr(1, LCase(olAtt.fileName), vCriteria(i)) > 0 Then
'do something with olatt
'or do something withy item
End If
Next i
Next olAtt
End If
End If
lbl_Exit:
Exit Sub
End Sub