Or in IF doesn't work...

I

info

I found this function in this group, and trying to use in my macro,
But I have problem with this line...
If Contains(Item.To, "Marcus") Or Contains(Item.To, "Info") Then

What is wrong?

CODE
************************************
Public Function Contains(spBody, ParamArray spText() As Variant) As
Boolean
Dim slText As Variant
For Each slText In spText()
If InStr(spBody, slText) Then
Contains = True
Exit For
End If
Next
End Function
************************************
Private Sub colSentItems_ItemAdd(ByVal Item As Object)
If Item.Class = olMail Then
Dim intRes As Integer
Dim strMsg As String
If Contains(Item.To, "Lisa") Or Contains(Item.To, "Anna") Then
strMsg = "Do you set a Orange flag with follow up in 7 days to
this message in Sent Items?"
intRes = MsgBox(strMsg, vbYesNoCancel + vbDefaultButton1, "Set
flag")
Select Case intRes
Case vbNo
'Do nothing
Case vbCancel
Cancel = True
Case vbYes
Item.FlagIcon = olOrangeFlagIcon
Item.FlagStatus = olFlagMarked
Item.FlagDueBy = Now + 7
Item.FlagRequest = "Follow up"
End Select
End If
Item.Save
End If
End Sub
************************************
 
M

Michael Bauer [MVP - Outlook]

Do you get an error?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

Am 17 Nov 2006 06:32:15 -0800 schrieb (e-mail address removed):
 
I

info

Well no, but nothing happens. I forgot to mention what I want to do,
the macro ask if I want to add a flag to the maill in the sent box if
it match the criteria. And that there the problem is, it doesn't ask.
So there has to be something wrong with the IF statment.

Michael Bauer [MVP - Outlook] skrev:
 
M

Michael Bauer [MVP - Outlook]

I don't see any error in the code. So probably the To property contains
neither "Lisa" nor "Anna".

BTW: You waste the benefit of that function by calling it twice for the same
property. You should either call InStr directly or call the Contains
function like this:

If Contains(Item.To, "Lisa", "Anna") Then...

The InStr function in your sample is case-sensitive. If you don't want to
care about upper or lower cases then use:

If InStr(1, spBody, slText, vbTextCompare) then ...


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

Am 20 Nov 2006 04:59:24 -0800 schrieb (e-mail address removed):
Well no, but nothing happens. I forgot to mention what I want to do,
the macro ask if I want to add a flag to the maill in the sent box if
it match the criteria. And that there the problem is, it doesn't ask.
So there has to be something wrong with the IF statment.

Michael Bauer [MVP - Outlook] skrev:
Do you get an error?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top