Solved

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

Posted on 2010-09-09
2
237 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
To show how to generate a certificate request 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 Servers >> Certificates…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

10 Experts available now in Live!

Get 1:1 Help Now