+ Reply to Thread
Results 1 to 10 of 10

Extract outlook message body text with VBA from Excel

  1. #1
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Extract outlook message body text with VBA from Excel

    Hi all,

    I have a number of Outlook .msg files saved to a shared folder (ie outside of Outlook). I am trying to write some VBA in Excel that extracts the message body text from each in turn (as a string)...and then does some other stuff with the contents of the string.

    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...

    Please Login or Register  to view this content.
    Thanks

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Extract outlook message body text with VBA from Excel

    Please Login or Register  to view this content.



  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Extract outlook message body text with VBA from Excel

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Re: Extract outlook message body text with VBA from Excel

    Thanks snb, but I have to admit I don't understand what this code is doing, so I'm not sure how I can make use of it!

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Extract outlook message body text with VBA from Excel

    It looks in evey post in the PostIN folder and reads the bodytext; puts it into the variable c01 and eventually writes all bodytexts in cell A1.

  6. #6
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Re: Extract outlook message body text with VBA from Excel

    Sorry snb I think I haven't been clear about my task. The email messages I need to extract from are in a windows folder on a shared drive, so they are not in an email folder within Outlook. These are emails from various sources that different users have dragged into the folder from outlook.

  7. #7
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Extract outlook message body text with VBA from Excel

    I am not sure but you may be able to use the CreateItemFromTemplate method in outlook to create an email based on the saved .msg file, then simply grab the Body property of that item and discard the item.
    Good luck.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Extract outlook message body text with VBA from Excel

    In line with @onerrors's idea: why don't you let those users send their emails to you. With the code I provided you can read the bodytext of those mails.

    But if you insist in using the msg files:
    You can open them simply using:

    Please Login or Register  to view this content.
    Last edited by snb; 01-29-2012 at 10:13 AM.

  9. #9
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Extract outlook message body text with VBA from Excel

    Quote Originally Posted by snb View Post
    In line with @onerrors's idea: why don't you let those users send their emails to you.
    I do not to be honest see how that relates at all to what I was suggesting?
    I am suggesting automating Outlook and using the stored .msg files as templates to create a copy of the stored emails so that the asker can read the body in code. It has the advantage over Shell that you get a direct reference to that email - I am not sure how you would do that with Shell?
    Last edited by OnErrorGoto0; 01-29-2012 at 10:59 AM.

  10. #10
    Registered User
    Join Date
    01-28-2007
    Location
    Reading, Berkshire, UK
    Posts
    26

    Re: Extract outlook message body text with VBA from Excel

    Hello both,

    I used "Set MyMail = MyOutlook.CreateItemFromTemplate(fileName)" as suggested and this worked perfectly. Thanks very much for this advice.

    Yes I realise it's strange I'm accessing these in a shared folder. It's because I'm getting information in a number of forms, sometimes in the body of an email, sometimes in text files, and sometimes in word documents. So I wanted to be able to dump all the different file types in one folder and then automate the text extraction for them all at once. So this why I'm not doing it from the body of emails within outlook.

    thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1