Saving the body of an email

alcibiades

New member
Local time
Today, 08:38
Joined
Jul 27, 2010
Messages
4
I have the following code to save e-mails from outlook to a text file, however, I want to save the body of the e-mail only. The problem is when .msg converts to .txt, the saved text file has a bunch of wingdings & corrupted data. I'm hoping that saving the body of the message only will solve this problem. Thank you in advance for your help.

Dim myOlapp As Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myFolder As Outlook.MAPIFolder
Dim myItem As Outlook.MailItem
Set myOlapp = CreateObject("Outlook.Application")
Set myNameSpace = myOlapp.GetNamespace("MAPI")
Set myFolder = myNameSpace.Folders("Mailbox - Inbox").Folders("Inbox")

For Each myItem In myFolder.Items
If InStr(myItem.Subject, "E-mail Subject") And myItem.SentOn > Date Then
myItem.SaveAs "Y:\Email.txt"
myItem.UnRead = False
End If
Next
 
Not sure with that method, but this:

strBody = myItem.Body

would put the body into a variable. From there you can do whatever you want with it. I'd start by looking at the CreateTextFile method in VBA help to create a text file.
 

Users who are viewing this thread

Back
Top Bottom