0
votes

I'm trying to make a macro / script, that will take my selected outlook mails, and save them to a .txt file.

I've actually got it to save it correctly with 1 mail selected, but the problem is that the formatting got all messed up, and started cutting up words - Heres the code I've used:

Sub SaveSelectedMailAsTxtFile()
 Const OLTXT = 0
  Dim currentExplorer As Explorer
  Dim Selection As Selection
  Dim oMail As Outlook.MailItem
  Dim obj As Object
  Dim sPath As String
  Dim dtDate As Date
  Dim sName As String


  Set currentExplorer = Application.ActiveExplorer
    Set Selection = currentExplorer.Selection

 For Each obj In Selection
  Set oMail = obj
  sName = oMail.Subject


  oMail.SaveAs "C:\path\file.txt", OLTXT

  Next

End Sub

Private Sub ReplaceCharsForFileName(sName As String, _
  sChr As String _
)
  sName = Replace(sName, "/", sChr)
  sName = Replace(sName, "\", sChr)
  sName = Replace(sName, ":", sChr)
  sName = Replace(sName, "?", sChr)
  sName = Replace(sName, Chr(34), sChr)
  sName = Replace(sName, "<", sChr)
  sName = Replace(sName, ">", sChr)
  sName = Replace(sName, "|", sChr)
End Sub

2 Problems -

1 Is that I cant select multiple mails, and save them to 1 text file.

2 The formatting of the mail gets cut up alot. For example, I got this product name:

"Dansk kolloid sølv 1 liter, fremstillet i København" -

copy pasted from outlook mail.

In the text file i get from the script, its printed like this:

Da nsk koll oid søl v 1 liter , fre mst illet i Kø ben hav n

Which makes it kinda hard to work with :S Any suggestions? Any help would be grately appreciated :)

Bonus info: I've tried doing another work around, where I select multiple emails, and just use outlook's save as function. Now if I choose mails containing plain text, I get the same issue - However, If I choose the same order email, combined with an email from say Humble Bundle or Twitch (I think they are HTML based emails? not sure tho), and save these emails, the formatting is untouched in the text based emails, and therefore useable.

1

1 Answers

0
votes
  1. Outlook does not save multiple items in a single file. It is your responsibility to merge multiple files if that is what you want.

  2. Is that what you see for the Body property in Outlook? You can check its value in OutlookSpy - select the message, click Item property, select the Body property.