"Save Message as Text" Macro Question

  • Thread starter Thread starter Vasilije Petkovic
  • Start date Start date
V

Vasilije Petkovic

Hello All,

I need to create an Outlook Macro that will do the following:

1) Open all messages in "Local Inbox Archive" Folder in my Outlook XP
2) Save the messages as text files in "C:/data" folder
3) Delete the messages from "Local Inbox Archive"

I would appreciate any help (or code) posted in this forum.

Thanks,

Vasa
 
Can't help but would like to know how to do this too. I think we're trying
to solve the same problem !
 
Sue,

Can you post your findings if you get an answer. I'll do the same.

Vasa
 
The best I have so far is to drag and drop as a .msg file, but it is still an
outlook file and although can be opened by Notepad or Word, there is still
too much code!
There is a piece of software you can buy, at this link
http://tinyurl.com/4uf83. Don't know anything about it, I got sent the info.
 
Hi Vasa,

here is a sample you can use. It only works, if the folder "c:\data\"
exists already.

Attention: The code only treats MailItems, Attachments are ignored.

Take a look at the comment line 'obj.Delete. I would suggest, you try
the code first, and only if it´s working as you want to, delete the
mails.

'<DieseOutlookSitzung>
Public Sub LoopMailFolder()
On Error GoTo ERR_HANDLER
Dim oFld As Outlook.MAPIFolder
Dim obj As Object

Set oFld = Application.Session.PickFolder
If Not oFld Is Nothing Then
For Each obj In oFld.Items
If TypeOf obj Is Outlook.MailItem Then
If ExportMailToTxt(obj) Then
'obj.Delete
End If
End If
Next
End If
Exit Sub
ERR_HANDLER:
MsgBox Err.Description, vbExclamation
End Sub

Public Function ExportMailToTxt(oMail As Outlook.MailItem) As Boolean
On Error Resume Next
Dim sPath As String: sPath = "c:\mails\"
Dim sName As String
Dim sFile As String
Dim dtDate As Date

sName = oMail.Subject
ReplaceCharsForFileName sName
dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyymmdd", vbMonday, vbFirstJan1) _
& Format(dtDate, "-hhnnss", vbMonday, vbFirstJan1) _
& "-" & sName & ".txt"
oMail.SaveAs sPath & sName, olTXT
ExportMailToTxt = (Err.Number = 0)
End Function
'</DieseOutlookSitzung>
 
Back
Top