-
Solved: Copy Attachments In A Folder
I want to copy attachments from every incoming mail in my inbox or a pst folder. to my HD. The e-mail has 2 attachments and I want to split them to 2 different folders. I have found an add in program (attachments_processor) but I want to do it with VBA.
Thanks,
-
The following code will save attachments to a folder.
I'm sure it could be adapted to save to 2 folders.
How are you determining which attachment goes to which folder?
[vba]
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[/vba]
-
The attachments in every e-mail are the same. So the 2 attachments have 2 different names. Maybe with the extension *.txt ?
I try it works but I want to copy attachments only from one folder.
Thanks!
-
Sorry I don't understand.
If you want help in saving to different folders you will need to tell use how you would work out which attachment would go to which folder.
-
First of all I want to save all attachments not from inbox but from another folder in outlook eg. temp. I have made a roule and every mail contains an attachment goes there.
After I want to split attachments in 2 different folders in my hard disk.
I also want to start the macro when outlook starts.
Thanks again..
-
Could you please give more information?
You still haven't stated either the names of the folders to save to or how to determine which attachment goes to which folder.
It's kind of hard to help without that information, and my mind reading powers tend to wane at this late hour(1130PM).
-
Ok then. The name of the outlook folder will be "temp". The name of the 2 folders in H.D. will be c:/Folder1 and C:/Folder2. The attachment with extansion attach*.txt goes in folder1 and oper*.xls in folder 2.
I didnt stated the names of folders because they may change (i can change them from the code, if I have an example. The first letters of the files willl be the same.
Thanks again for your time.
-
Any ideas? I want to copy attachments in a folder. I have 2 mailboxes (exchange server)and I want to apply the roule in the 2nd mailbox and not in the basic one.
Thanks
-
Hi there
Maybe this KB entry might be of some use.
You won't need to the reference to XL or the Print Attachments part but it should get you started in the right direction
K :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules