Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-09
2
Medium Priority
?
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
Tony Massa earned 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
In this video we show how to create an email address policy 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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

688 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