How to copy a email attached to a specific folder ?
Hi
Please advice me how to copy a email attached fle to a specific folder automatically.
I want to do it using my VBA code. Check for the attached file via email , if exist then copy the file/files to a specific folder. Please provide me VBA code to do that function automatically.
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
I created this vba sub and then used it in a custom rule in Outlook to copy all the attachments to the folder when the subject had my key words in it...
Public Sub CopyAttachment(msg As MailItem) Dim id As String Dim ns As Outlook.NameSpace Dim m As Outlook.MailItem Dim fileName As String Dim attach As Outlook.Attachment Dim i As Integer Const path = "C:\Email Attachments\" id = msg.EntryID Set ns = Application.GetNamespace("MAPI") Set m = ns.GetItemFromID(id) For Each attach In m.Attachments fileName = path & Strings.Format(DateTime.Now, "MM-dd-yy_hhmmss") & "_" & _ Strings.Format(i) & "_" & attach.fileName attach.SaveAsFile fileName i = i + 1 m.UnRead = False Next attach 'Clean Up Set ns = Nothing Set m = Nothing Set attach = NothingEnd Sub
Thanks for your advice with the VBA code, would you please advice how to filter by date, for example copy the all attachment to a specific folder of today 03/07/2011. To do so what need to add in VBA code. Thanks for you co-operation.
TMWSIY
I just use a rule that processes each inbound email. You can state what emails you want to process as they arrive (filter by to, from, subject, etc).
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
alam747
ASKER
I tried your VBA code but facing compile error in GetNamespace "Method or data member not found"
please advice how to solve this problem ...how to fix it..
Thanks
TMWSIY
Where are you getting the error? What method or data member is not found? What version of outlook are you using? Did you put the code in a new module?
alam747
ASKER
I am using outlook 2003. I fix it and now I can copy the attached file from my inbox to a specific folder. Actually, I want to copy the email attached file from a public email inbox folder.Please advice how to do that,where to change to copy the attached file from a public inbox folder.
Thanks..
Open in new window