If a .msg file is ok for your purposes, you should use it as it saves the attachments as part of the file. You can save the messages as other filetypes (txt, doc, rtf, html, etc), but then you have to handle the attachments seperatly.
You can use the following code to export all messages from a folder that you choose. You will need to copy this into the Outlook VBA editor. Have your outlook activated and press Alt-F11 to bring up the VBA window. Paste the code in there. Change the 'strFilePath = "C:\Data\Email\"' to the folder you want to export to. This can be a network drive as well (strFilePath = "\\Sample\Network\Drive\). Make sure that the folder exists already and that you put the final backslash '\' at the end of the string.
Once this is done you can run the code by choosing the Tools\Macro\Macros... option from the outlook application and selecting the ExportMail macro. This will pop up a window where you can select the mailbox to export.
Code:
Public Sub ExportMail()
On Error Resume Next
Dim otlNameSpace As Outlook.NameSpace
Dim otlFolder As Outlook.MAPIFolder
Dim oltAttachment As Outlook.Attachment
Dim intMessageNumber As Integer
Dim otlMailItem As Outlook.MailItem
Dim strFilePath As String
Dim strSubject As String
strFilePath = "C:\Data\Email\"
'get reference to inbox
Set otlNameSpace = Outlook.GetNamespace("MAPI")
Set otlFolder = otlNameSpace.PickFolder
For Each otlMailItem In otlFolder.Items
'change illegal file characters to underscore
strSubject = Replace(otlMailItem.Subject, "/", "_", 1)
strSubject = Replace(strSubject, "\", "_", 1)
strSubject = Replace(strSubject, ":", "_", 1)
strSubject = Replace(strSubject, "*", "_", 1)
strSubject = Replace(strSubject, "?", "_", 1)
strSubject = Replace(strSubject, "chr(34)", "_", 1)
strSubject = Replace(strSubject, "<", "_", 1)
strSubject = Replace(strSubject, ">", "_", 1)
strSubject = Replace(strSubject, "|", "_", 1)
intMessageNumber = intMessageNumber + 1
Debug.Print strFilePath & strSubject & "_" & intMessageNumber & ".msg"
otlMailItem.SaveAs strFilePath & strSubject & "_" & intMessageNumber & ".msg", olMSG
Next otlMailItem
Set oltAttachment = Nothing
Set otlMailItem = Nothing
Set otlFolder = Nothing
Set otlNameSpace = Nothing
MsgBox "Exported " & intMessageNumber & " files."
End Sub
Bookmarks