• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

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.

Your prompt response would be highly appreciated.
0
alam747
Asked:
alam747
  • 4
  • 3
1 Solution
 
James MurrellProduct SpecialistCommented:
0
 
TMWSIYCommented:
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 = Nothing

End Sub

Open in new window

0
 
alam747Author Commented:
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.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
TMWSIYCommented:
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).
0
 
alam747Author Commented:
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
0
 
TMWSIYCommented:
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?
0
 
alam747Author Commented:
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..
0
 
TMWSIYCommented:
Are you talking about public folders in exchange that you access through outlook?  Is this a one time thing or will it be used on an ongoing basis?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now