Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
In this video we show how to create a Distribution Group 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 Recipients >>…

758 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

20 Experts available now in Live!

Get 1:1 Help Now