Solved

outlook 2007 - sort incoming email - if sunject = 'x' write to a text file else end program

Posted on 2010-09-09
2
236 Views
Last Modified: 2012-06-27
I am looking for a program that will sort incoming email thru outlook.  if subject = ' x' then save it to a text file in separate columns. one column for each: to, from , suject, message.


--->>>actually i wanted this on the server, but cant have a copy of outlook on the exchange..so my only solution is to have the exchange send to client..client sorts email...then if subject = 'x' then save to text, as I dont know if exchange can save to a text file.


here is what I have so far:

Sub SaveAsTXT_if_SUBJ_equals_X()
    Dim myItem As Outlook.Inspector
    Dim objItem As Object
    Dim strname as stirng

    strname = objItem.Subject
    Set myItem = Application.ActiveInspector


    If strname = "X" Then
        Set objItem = myItem.CurrentItem      

        objItem.SaveAs Environ("HOMEPATH") & "\My Documents\" &  strname & ".txt", olTXT
     
    Else
        MsgBox "There is no current active inspector."
    End If
End Sub
0
Comment
Question by:GlobaLevel
2 Comments
 
LVL 17

Accepted Solution

by:
Tony Massa earned 500 total points
ID: 33643258
Here's a sample that may get you what you need.  What will you do with the messages?  This script will check every message in the Inbox every time, so if the messages still reside in the inbox, you'd get duplicate date when the script runs again, unless you create a new output file each time.

Also, choose your delimiter wiseley, since some of the message body may contain tabs, commas, semicolons, etc.  You could choose a delimeter like "~" and import into Excel using it as the specified delimeter.
Const ForWriting = 2

Const olFolderInbox = 6

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objResults = objFSO.CreateTextFile("Output.txt", ForWriting)

strDelim = "~"

Set objOutlook = CreateObject("Outlook.Application")

Set objNamespace = objOutlook.GetNamespace("MAPI")



strSubject = "Your Subject Here"



Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

Set colItems = objFolder.Items



For Each objItem in colItems

  If objItem.Subject = strSubject Then

    objResults.Writeline objItem.To & strDelim & objItem.Sender & _

    strDelim & objItem.Subject & strDelim & objItem.Body

  End If

Next



WScript.Echo "Done"

Open in new window

0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 33643334
well simplicity...the emails can stay in the inbox...and can be deleted at the end of the month...

I need the code to check the subject line for a special charset or a split as the subject line will contain: "abc.com"...but when they reply...it will contain the forward so it should factor that in like: "FW:abc.com - your response to your acct" so it has to find the abc.com in there...if found sort to the text file...

this looks like vbscript...but I need VBA to put in a module inside the Outlook VBE....
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Read this checklist to learn more about the 15 things you should never include in an email signature.
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now