?
Solved

How to copy a email attached to a specific folder ?

Posted on 2011-03-05
8
Medium Priority
?
461 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 31

Accepted Solution

by:
James Murrell earned 2000 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Viewers will learn the different options available in the Backstage view in Excel 2013.
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 …

777 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