View Full Version : VBA assistance for outlook 2003
lsorsby
07-29-2012, 11:38 AM
i have viewed some scripts that enable me to extract emails from a folder on outlook and turn them into text files however. is it possible to to do this for only incoming emails? not existing emails? i need this to match a certain subject. can somebody let me know how i could achieve this or if they know of a tutorial?
thanks
JP2112
08-06-2012, 07:15 AM
Sure, just adapt this code. You'll need to include the conditions that filter the emails you want to save, and calculate the filepath to save the emails.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
On Error Goto ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = "MailItem" Then
Set Msg = item
' what emails do you want to act on?
Msg.SaveAs "path and filename", olTXT
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Paste the code into the ThisOutlookSession module and restart Outlook.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.