PDA

View Full Version : Attachments saved and removed



bdacus
02-29-2008, 12:57 PM
Ok all:

I have tried every attachment piece of code here. What i am looking for is this..
Save every attachment that comes though my inbox. To a folder on the hd and then remove the attachment from the email. So if you send me an email with an attachment of any kind put it in the folder and remove it from the you just sent.

The only one that comes close is this one..


Sub SaveAttachments()
Dim myOlapp As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolders
Dim myFolder
Dim myItem
Dim myAttachment As Outlook.Attachment
Set myOlapp = CreateObject("Outlook.Application")
Set myNameSpace = myOlapp.GetNamespace("MAPI")

For Each myFolders In myNameSpace.Folders
For Each myFolder In myFolders.Folders
For Each myItem In myFolder.Items
If TypeName(myItem) = "MailItem" Then
If myItem.Attachments.Count <> 0 Then
For Each myAttachment In myItem.Attachments
myAttachment.SaveAsFile "C:\MailTest\" & myAttachment.FileName
Next
End If
End If
Next
Next
Next
End Sub