A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Or in IF doesn't work...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 17th 06, 02:32 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 7
Default Or in IF doesn't work...

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
************************************

Ads
  #2  
Old November 20th 06, 05:35 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Or in IF doesn't work...



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 :

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
************************************

  #3  
Old November 20th 06, 12:59 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 7
Default Or in IF doesn't work...

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?

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


  #4  
Old November 21st 06, 06:12 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Or in IF doesn't work...



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 :

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?

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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using OR in IF doesn't work... [email protected] Outlook - General Queries 2 November 17th 06 03:15 PM
How do I customize my work week if I work different hours daily? Pratherer Outlook - Calandaring 1 October 31st 06 05:57 AM
did it work Romulus R Johnson Outlook Express 0 October 27th 06 03:39 PM
e-mail alerts don't work,setup but don't work- Studmn1 Outlook - General Queries 3 August 24th 06 09:38 PM


All times are GMT +1. The time now is 07:45 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.