Newbie needs help

Status
Not open for further replies.
J

Jim

I am trying to save the body of an email to a text file using vba code

Would someone kindly post the code so that I can use it as a worked example

I'm using WinXP and Outlook 2003

Regards & TIA
 
C

Charlize

VBA Code:

------------------
Sub save_selection_mails_to_txt()

'The message you want to process

Dim MyMessage As Outlook.MailItem

'a number

Dim myItem As Long

Dim save_it As String

'if selection isn't present, don't do a thing

'you could build an extra check if the class

'of the selected item is a message or not

'because there are read receipt and taskitems in mailbox

If ActiveExplorer.Selection.Count < 1 Then

MsgBox "Select at least one mailmessage", vbInformation

Exit Sub

End If

For myItem = 1 To ActiveExplorer.Selection.Count

Set MyMessage = ActiveExplorer.Selection.item(myItem)

save_it = MyMessage.ReceivedTime

'when using dates with /

save_it = Replace(save_it, "/", "_")

'when using hours with :

save_it = Replace(save_it, ":", "-")

'c:\txt-mails must be present as a directory

MyMessage.SaveAs "c:\txt-mails\" & save_it & " -- " & MyMessage.SenderName & ".txt", olTXT

'go to next selected mail

Next myItem

End Sub

------------------
Charlize
 
J

Jim

Many thanks ... That is exactly what I needed to get me started.

Regards

Jim
 
Status
Not open for further replies.
Top