I have a huge number of Outlook .msg and Outlook .eml files saved to a shared network folder (ie outside of Outlook). I am trying to write some VBA in Excel that extracts the Subjects,Sender, CC, Receiver, SentTime, SentDate, message body text from each file and import these info to Excel cells orderly
Subject Sender CC Receiver SentTime SentDate
Re:.. Mike Jane Tom 12:00:00 23 Jan 2013
I've done a similar thing with word documents but I'm struggling to 'get at' the text in the .msg files.
So far I have the code below. I like to think I'm on the right track at least, but I'm stuck at the line where I'm trying to set up a reference to the msg file. Any advice will be appreciated...
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Set MyOutlook = New Outlook.Application
Set MyMail =
Dim FileContents As String
FileContents = MyMail.Body
Regards
Assuming you know, or can compute the full filename & path for the .msg :
' The code below will be able to work with almost all messages from Outlook, ' except and I don´t know why if you are working with messages generated by ' Exchange Server such as "Mail Delivery System". It does looks like it is not a ' really message at this point. If you try to read it the object "olItem" is 'always Empty. However if you get this alert "Mail Delivery System" and forward 'to yourself and then try to read it, it does work fine. Don´t ask me 'why because I have no idea. I just think that this "Mail Delivery System" 'at first time it is an alert and not a message, also the icon does change, it 'is not an envelop icon but a delivery with success or not icon. if you have ' any idea how to handle it, please adivise
so I've been able to get it working with .msg files saved outside of outlook. However, as I don't have access to Outlook Express I have no way of saving any .eml files at the moment. Here's a Sub I've come up with that will insert Subject,Sender,CC,To, and SendOn into an excel worksheet starting at row 2 column 1 (assuming a header row at row 1):
which uses the GetFileList function as defined below (thanks to spreadsheetpage.com)
Should be fairly straightforward, let me know if you need any more explanation.
Edit: You'll also have to add a reference to the outlook library
HTH!
Z