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

Move mail to a folder based on 2 different words in the subject fi



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 13th 06, 11:47 AM posted to microsoft.public.outlook.program_vba
Alan Kirkham
external usenet poster
 
Posts: 2
Default Move mail to a folder based on 2 different words in the subject fi

When an e-mail arrives that has 2 specific words in the subject field, I
would like the mail to be moved to a personal archive folder. The 2 words are
not next to each other. For example, Subject field is "This is a test mail",
and the 2 words that I want to look for are "This" and "mail".

The script below is one that works if only 1 word is being checked and
renames the subject line.

Sub ChangeSubjectName(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' do stuff with olMail, e.g.

If olMail.Subject = "test" Then
olMail.Subject = "whatever you want the subject to be"
olMail.Save
End If

Set olMail = Nothing
Set olNS = Nothing
End Sub
Ads
  #2  
Old February 13th 06, 09:41 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Move mail to a folder based on 2 different words in the subject fi

Use multiple InStr expressions to evaluate whether the desired words are
present in the Subject line and continue your logic if they all satisfy your
criteria.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Alan Kirkham" wrote:

When an e-mail arrives that has 2 specific words in the subject field, I
would like the mail to be moved to a personal archive folder. The 2 words are
not next to each other. For example, Subject field is "This is a test mail",
and the 2 words that I want to look for are "This" and "mail".

The script below is one that works if only 1 word is being checked and
renames the subject line.

Sub ChangeSubjectName(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' do stuff with olMail, e.g.

If olMail.Subject = "test" Then
olMail.Subject = "whatever you want the subject to be"
olMail.Save
End If

Set olMail = Nothing
Set olNS = Nothing
End Sub

  #3  
Old February 14th 06, 03:34 PM posted to microsoft.public.outlook.program_vba
Alan Kirkham
external usenet poster
 
Posts: 2
Default Move mail to a folder based on 2 different words in the subjec

Thank you for your reply Eric. The InStr expression pushed me in the right
direction and I was able to solve my query. Below is the finished script.
Thanks again.

'***********************************

Sub MoveMail(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim IMAPMoveMail As MAPIFolder
Dim Strtest1
Dim Strtest2

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
Set objNS = Application.GetNamespace("MAPI")
Set IMAPMoveMail = objNS.Folders("Personal Intel").Folders("atest")

' do stuff with olMail, e.g.

Strtest1 = "test1"
Strtest2 = "test2"

If InStr(olMail.Subject, Strtest1) And InStr(olMail.Subject, Strtest2)
Then
olMail.Move IMAPMoveMail
'olMail.Save
End If

Set olMail = Nothing
Set olNS = Nothing
End Sub

'************************************************* *****

"Eric Legault [MVP - Outlook]" wrote:

Use multiple InStr expressions to evaluate whether the desired words are
present in the Subject line and continue your logic if they all satisfy your
criteria.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Alan Kirkham" wrote:

When an e-mail arrives that has 2 specific words in the subject field, I
would like the mail to be moved to a personal archive folder. The 2 words are
not next to each other. For example, Subject field is "This is a test mail",
and the 2 words that I want to look for are "This" and "mail".

The script below is one that works if only 1 word is being checked and
renames the subject line.

Sub ChangeSubjectName(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' do stuff with olMail, e.g.

If olMail.Subject = "test" Then
olMail.Subject = "whatever you want the subject to be"
olMail.Save
End If

Set olMail = Nothing
Set olNS = Nothing
End Sub

 




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
how can i move a messeage to a certain folder before reading it? Bilal Outlook - Installation 1 February 22nd 06 01:24 PM
Outlook Folder Move Event Atul Sureka Outlook and VBA 0 February 13th 06 06:09 AM
Cannot move/delete messages from Sent folder KBAR Outlook Express 1 February 10th 06 04:49 PM
move mail to storage folder TuckerWheaten Outlook Express 4 January 18th 06 02:22 PM
2 questions; unable 2 select words & get hotmail Mar Outlook - Installation 1 January 16th 06 05:55 PM


All times are GMT +1. The time now is 08:37 PM.


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.