Solved

How to copy a email attached to a specific folder ?

Posted on 2011-03-05
8
457 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
ID: 35046319
0
 
LVL 6

Expert Comment

by:TMWSIY
ID: 35056758
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
ID: 35058720
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 6

Expert Comment

by:TMWSIY
ID: 35059447
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
 

Author Comment

by:alam747
ID: 35063657
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
ID: 35068683
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
ID: 35090095
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
ID: 35094255
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Skype for Business 10 78
Adding to open record on form, from unbound textbox 4 49
iPhone excel activation issues 11 91
Where is user Lync data stored 4 84
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…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
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 …

776 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