PDA

View Full Version : Solved: Copy Attachments In A Folder



ermis1975
10-22-2005, 10:53 AM
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,

Norie
10-22-2005, 12:10 PM
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?

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

ermis1975
10-22-2005, 01:56 PM
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!

Norie
10-22-2005, 02:31 PM
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.

ermis1975
10-22-2005, 03:10 PM
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..

Norie
10-22-2005, 03:32 PM
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).:)

ermis1975
10-23-2005, 12:37 AM
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.

ermis1975
11-15-2005, 03:59 AM
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

Killian
11-15-2005, 08:58 AM
Hi there :hi:
Maybe this KB entry (http://vbaexpress.com/kb/getarticle.php?kb_id=522) 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