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

Creating macro that will sort emails into folders based on text in body



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 29th 06, 09:58 PM posted to microsoft.public.outlook.program_vba
mugginns
external usenet poster
 
Posts: 1
Default Creating macro that will sort emails into folders based on text in body

I'm trying to find a good spot to find info on how to create a macro
that will basically look through the body of an email and sort it into
a folder based on finding a string, ie:

hospid= 102341

It would then be sent to a folder, ie:

hosp11

I'm a little new at programming for Outlook and was wondering if anyone
can help me out. I had looked at a post on outlookcode.com that
basically creates your own rules but i could not get this to work at
all, and I'm not sure if it was searching the body for the information
or not.

michael

  #2  
Old September 29th 06, 11:34 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default Creating macro that will sort emails into folders based on text in

Here's some sample code that can move an e-mail to the folder you choose if
it contains the specified text in the message body:

Dim objMail As Outlook.MailItem

'Look for open item window
If ActiveInspector Is Nothing Then Exit Sub
'Look for open e-mails only
If ActiveInspector.CurrentItem.Class olMail Then Exit Sub
Set objMail = ActiveInspector.CurrentItem

If InStr(objMail.Body, "Look for this text") 0 Then
'will move to the folder you choose
Call objMail.Move(Application.GetNamespace("MAPI").Pick Folder)
'You can replace the above Move argument with a MAPIFolder object
directly instead of choosing one
'Use NameSpace.GetDefaultFolder to easily get a reference to a
default Outlook folder
If Err.Number 0 Then
'A folder wasn't chosen, or a non-email folder was chosen
End If
End If

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"mugginns" wrote:

I'm trying to find a good spot to find info on how to create a macro
that will basically look through the body of an email and sort it into
a folder based on finding a string, ie:

hospid= 102341

It would then be sent to a folder, ie:

hosp11

I'm a little new at programming for Outlook and was wondering if anyone
can help me out. I had looked at a post on outlookcode.com that
basically creates your own rules but i could not get this to work at
all, and I'm not sure if it was searching the body for the information
or not.

michael


  #3  
Old September 30th 06, 08:05 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Creating macro that will sort emails into folders based on text in body

Am 29 Sep 2006 12:58:37 -0700 schrieb mugginns:

This basic loops through the Inbox. The loop counts backwards because I
guess that you want to move found items off that list.

Dim Item as Object
Dim Folder as Outlook.MapiFolder
Dim Target as Outlook.Folder
Dim i as Long
Dim Find as string

Set Folder=Application.GetDefaultFolder(olFolderinbox)

Find="hospid= 102431"

' If hosp11 is a subfolder of the Inbox
Set Target = Folder.Folders("hosp11")

For i=Folder.Items.Count To 1 Step-1
Set Item=Folder.Items(i)
If Instr(1, Item.Body, Find, vbTextCompare) Then
Item.Move Target
Endif
Next

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


I'm trying to find a good spot to find info on how to create a macro
that will basically look through the body of an email and sort it into
a folder based on finding a string, ie:

hospid= 102341

It would then be sent to a folder, ie:

hosp11

I'm a little new at programming for Outlook and was wondering if anyone
can help me out. I had looked at a post on outlookcode.com that
basically creates your own rules but i could not get this to work at
all, and I'm not sure if it was searching the body for the information
or not.

michael

  #4  
Old October 2nd 06, 03:08 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 2
Default Creating macro that will sort emails into folders based on text in body

Thanks for the help gentlemen. I'm looking at the code, and I'm looking
specifically at:

'You can replace the above Move argument with a MAPIFolder object
directly instead of choosing one
'Use NameSpace.GetDefaultFolder to easily get a reference to a
default Outlook folder

Basically I want to send the file to a folder called "blank1" that I
have created in my Inbox. I have looked and looked but I cannot
understand how to use this. Can you help explain ?
Michael

 




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
Forward emails based on text in body of e-mail [email protected] Outlook and VBA 0 August 24th 06 05:37 PM
Outlook 2003 sending blank emails / text missing from body Keith Outlook - General Queries 3 June 1st 06 02:57 PM
Duplicate emails with different text body Martin Outlook - General Queries 2 May 28th 06 11:35 PM
I want to certify a macro based document & don't want to see Mess Parag Vidhate Outlook and VBA 1 May 27th 06 04:22 AM
Macro to Flag based on criteria [email protected] Outlook - General Queries 1 March 31st 06 03:04 AM


All times are GMT +1. The time now is 08:45 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.