+ Reply to Thread
Results 1 to 2 of 2

Copy Outlook email attachments to Local drive(specified Path)

Hybrid View

  1. #1
    Registered User
    Join Date
    12-31-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    19

    Copy Outlook email attachments to Local drive(specified Path)

    Hi All,

    I’m in search of a macro which should extract(Copy) the attachments of outlook mails to a Specified folder.

    I found a macro which is doing the extraction of attachments of outlook mails considering outlook mailbox as source. However, I need a macro whose source of mails is Local drive(Specified path).

    I've appended Excel file and Macro (which I’ve found in Internet) for your reference.

    Thanks in Advance

    Option Explicit
    
    Sub GetAttachments()
    ' This Outlook macro checks a the Outlook Inbox for messages
    ' with attached files (of any type) and saves them to disk.
    ' NOTE: make sure the specified save folder exists before
    ' running the macro.
        On Error GoTo GetAttachments_err
    ' Declare variables
        Dim ns As Namespace
        Dim Inbox As MAPIFolder
        Dim Item As Object
        Dim Atmt As Attachment
        Dim FileName As String
        Dim i As Integer
        Set ns = GetNamespace("MAPI")
        Set Inbox = ns.GetDefaultFolder(olFolderInbox)
        
     
        i = 0
    ' Check Inbox for messages and exit of none found
        If Inbox.Items.Count = 0 Then
            MsgBox "There are no messages in the Inbox.", vbInformation, _
                   "Nothing Found"
            Exit Sub
        End If
    ' Check each message for attachments
        For Each Item In Inbox.Items
    ' Save any attachments found
            For Each Atmt In Item.Attachments
            ' This path must exist! Change folder name as necessary.
                FileName = "C:\Users\Madhu\Desktop\test\" & Atmt.FileName  ''Destination Path Where all the attachments has to saved
                Atmt.SaveAsFile FileName
                i = i + 1
             Next Atmt
        Next Item
    ' Show summary message
        If i > 0 Then
            MsgBox "I found " & i & " attached files." _
            & vbCrLf & "I have saved them into the C:\Users\Madhu\Desktop\test folder." _
            & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
        Else
            MsgBox "I didn't find any attached files in your mail.", vbInformation, "Finished!"
        End If
    ' Clear memory
    GetAttachments_exit:
        Set Atmt = Nothing
        Set Item = Nothing
        Set ns = Nothing
        Exit Sub
    ' Handle errors
    GetAttachments_err:
        MsgBox "An unexpected error has occurred." _
            & vbCrLf & "Please note and report the following information." _
            & vbCrLf & "Macro Name: GetAttachments" _
            & vbCrLf & "Error Number: " & Err.Number _
            & vbCrLf & "Error Description: " & Err.Description _
            , vbCritical, "Error!"
        Resume GetAttachments_exit
    End Sub
    Attached Files Attached Files
    Last edited by Nanimadhu; 04-27-2014 at 09:45 AM.

  2. #2
    Registered User
    Join Date
    12-31-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Copy Outlook email attachments to Local drive(specified Path)

    Here is the attachment.Extract_Attachments.xlsm

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Group Email through Outlook with attachments
    By susuyesyes in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-15-2014, 04:30 PM
  2. Extract msg attachments from outlook email
    By haribo83 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-02-2012, 10:53 AM
  3. [SOLVED] Windows API to Determine if File is Local/Convert Path to Drive Letter
    By Johnny in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2006, 09:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1