Solved

How to copy a email attached to a specific folder ?

Posted on 2011-03-05
8
456 Views
Last Modified: 2012-06-27
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
Comment
Question by:alam747
  • 4
  • 3
8 Comments
 
LVL 31

Accepted Solution

by:
James Murrell earned 500 total points
Comment Utility
0
 
LVL 6

Expert Comment

by:TMWSIY
Comment Utility
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
 

Author Comment

by:alam747
Comment Utility
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
 
LVL 6

Expert Comment

by:TMWSIY
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:alam747
Comment Utility
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
 
LVL 6

Expert Comment

by:TMWSIY
Comment Utility
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
 

Author Comment

by:alam747
Comment Utility
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
 
LVL 6

Expert Comment

by:TMWSIY
Comment Utility
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now