?
Solved

how to combine multiple message texts into one text file

Posted on 2005-05-12
5
Medium Priority
?
221 Views
Last Modified: 2010-04-08
I have several thousand messages, each consisting of a single line of text... is there any good way to take the one line of text from each of these messages and combine them into a single text file?
0
Comment
Question by:jrcooperjr
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 13991501
Hi jrcooperjr,

Are the message alone in one folder or could they all be moved into one folder?  If so, then I can wput together a simple macro that'll go through them all and write them out into one text file.

Cheers!
0
 
LVL 1

Author Comment

by:jrcooperjr
ID: 13991527
They are all in one folder.....
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 13991776
jrcooperjr,

Here it is.  This macro will loop through all the messages in a given folder and write the contents of each message's body to a file, one line per file.  Of course if a message actually has more than one line in it, then this approach will write them all to the text file.  I wrote and tested this using Outlook 2002 and it worked perfectly.  Here's what you'll need to do to use this.
1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Modules and click on Module1
4.  Copy the code below and paste it into the right-hand pane of the VB editor window
5.  Edit the code as needed
6.  Click the diskette icon on the toolbar to save changes
7.  Close the VB Editor
8.  Click Tools->Macro->Security
9.  Set the Security Level to Medium
10.  Expand your folder list and click on the folder containing the messages
11.  Run the macro by clicking Tools->Macro->Macros->WriteTextToFile->Run
12.  When the "All done" message appears, go check the file and it should contain the contents of all the messages from that folder


Sub WriteTextToFile()
    Dim olRootFolder As MAPIFolder, _
        olExplorer As Outlook.Explorer, _
        olMessage As Outlook.MailItem, _
        objFSO As Object, _
        objFile As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Change the filename and path as desired
    Set objFile = objFSO.CreateTextFile("C:\eeTesting\Q_21422190.Txt")
    Set olExplorer = Application.ActiveExplorer
    Set olRootFolder = olExplorer.CurrentFolder
    For Each olMessage In olRootFolder.Items
        objFile.WriteLine olMessage.Body
    Next
    objFile.Close
    Set objFile = Nothing
    Set olMessage = Nothing
    Set olRootFolder = Nothing
    Set olExplorer = Nothing
    Set objFSO = Nothing
    MsgBox "All done."
End Sub
0
 
LVL 1

Author Comment

by:jrcooperjr
ID: 13992042
Thanks very much! Your code did exactly what I needed...
I'm also studying VB scripting, so your example helped me out there too...
0
 
LVL 76

Expert Comment

by:David Lee
ID: 13992144
No problem.  Glad I could help out.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Office 365 has multiple features and services which are specially designed to help businesses to reduce their dependence on on-premises IT resources. It also offers great flexibility and enhanced security. But like any other data, Office 365 mailbo…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

589 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