Closed Thread
Results 1 to 6 of 6

Excel Macro to download attachments from multiple sub folders of outlook

Hybrid View

Guest Excel Macro to download... 10-19-2010, 10:57 PM
Leith Ross Re: Excel Macro to download... 10-19-2010, 11:22 PM
Guest Re: Excel Macro to download... 10-19-2010, 11:38 PM
Leith Ross Re: Excel Macro to download... 10-19-2010, 11:55 PM
Guest Re: Excel Macro to download... 10-23-2010, 05:34 AM
Guest Re: Excel Macro to download... 10-31-2010, 09:32 AM
  1. #1
    abhay_547
    Guest

    Excel Macro to download attachments from multiple sub folders of outlook

    Hi All,

    I have the below macro which I got which downloads the attachments from a outlook folder which is created in Inbox .i.e. Inbox->Myfolder which means it is sub folder of Inbox but I have some sub sub folders for example Inbox->MyFolder->Abcfolder now I have such multiple subfolders from which I want to download the attachments every day. I want the macro to download only the latest files.

      
          Sub GetAttachments(MyMail As MailItem)
           On Error GoTo GetAttachments_err
           Dim ns As NameSpace
           Dim Inbox As MAPIFolder
           Dim SubFolder 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)
           Set SubFolder = Inbox.Folders("AutomationOutlook")
           i = 0
           If SubFolder.Items.Count = 0 Then
              MsgBox "There are no messages in the Inbox.", vbInformation, _
                      "Nothing Found"
              Exit Sub
           End If
            For Each Item In SubFolder.Items
              For Each Atmt In Item.Attachments
                 FileName = "C:\OutlookAttachments\" & Atmt.FileName
                 Atmt.SaveAsFile FileName
                 i = i + 1
              Next Atmt
           Next Item
           If i > 0 Then
              MsgBox "I found " & i & " attached files." _
                 & vbCrLf & "I have saved them into the C:\OutlookAttachments 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
          GetAttachments_exit:
             Set Atmt = Nothing
             Set Item = Nothing
             Set ns = Nothing
             Exit Sub
           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
    Thanks a lot for your help in advance.
    Last edited by abhay_547; 10-19-2010 at 11:01 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Macro to download attachments from multiple sub folders of outlook

    Hello abhay_457,

    Question also posted at http://www.mrexcel.com/forum/showthread.php?t=502933

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    abhay_547
    Guest

    Re: Excel Macro to download attachments from multiple sub folders of outlook

    Hi Ross,

    Apologies, I will ensure to post the link of any cross post done by me on any other forum in future.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Excel Macro to download attachments from multiple sub folders of outlook

    Hello abhay_457,

    Thanks. It helps everyone to know what solutions have been proposed. Posting links to others sites where you have asked the same question helps you get the answers you need and respects the time and effort of those helping you.

  5. #5
    abhay_547
    Guest

    Re: Excel Macro to download attachments from multiple sub folders of outlook

    Hi All,

    I have found a code which had resolved my one issue .i.e. my macro now downloads only the files with specific extensions like xls, xlsx, ppt etc. Earlier it use to download all attachments but still I have following issues which are still outstanding.

    1) Download the files from multiple subfolders .i.e. select the folder in tree view and use that selection in main macro to download attachments.
    3) Download only the latest files.

    I have selected the true for checkboxes in the property of treeview1 so that we can select the multiple folders.

    I also got the below code to get the selected folders of outlook as selection for downloading the attachments from them. I need help to incorporate this so that we can fix the issue no.1

    Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
      Dim n As Node
      
      If Node.Parent Is Nothing Then
        Set n = Node.Child
        Do Until n Is Nothing
          n.Checked = Node.Checked
          Set n = n.Next
        Loop
      End If
    End Sub
    I am attaching my updated macro file for your reference. please have a look.



    Thanks a lot for your help in advance.
    Attached Files Attached Files
    Last edited by abhay_547; 10-23-2010 at 05:40 AM.

  6. #6
    abhay_547
    Guest

    Re: Excel Macro to download attachments from multiple sub folders of outlook

    Hi All,

    Did anyone get the chance to look at the above post ?.


    Thanks a lot for your help in advance.

Closed Thread

Thread Information

Users Browsing this Thread

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

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