+ Reply to Thread
Results 1 to 3 of 3

Saving attachments in multiple emails in outlook 365

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-08-2011
    Location
    Lubbock, TX, USA
    MS-Off Ver
    MS OFFICE 365 EXCEL, OUTLOOK, WORD, POWERPOINT
    Posts
    196

    Saving attachments in multiple emails in outlook 365

    Hi, we just started a big project and my team leaders are sending in reports. The reports are attachments to an email. I know I can select one email and choose to save all attachments. But, with a couple of hundreds emails all with one or two attachments that is going to be a time suck. I tried selecting multiple emails and there's no option to save all the attachments.

    Does anyone have a workaround?
    Macros don't scare me either. I'm ok with Excel macros so I figure I have a shot at learning Outlook Macros...

    Thanks for looking.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Saving attachments in multiple emails in outlook 365

    I had to do this in a prior job, here is the code I used.

    This code reads an incoming subfolder directly under the INBOX, strips out the attachments to the specified Excel folder and then moves the mail to a processed folder that is directly under the subfolder

    Set up the parameters as named ranges. Look at the initialize variables section to get the names.

    The only thing that should need explanation is KeepFiles. It defines what kind of files you want to download separated by columns. So *.xlsx,*.csv will download XLSX files and CVS files if any but not PDF, JPEG or other types of files.

    Dim KeepFiles() As String               ' Type of files to keep
    Dim kf As Long                          ' Pointer to file types to keep
    
    Sub ProcessReport()
    Dim olApp As Object                     ' Outlook Application
    Dim olNS As Object                      ' Outlook Name Space
    Dim FldrIn As Object                    ' Dock Schedule folder
    Dim FldrOut As Object                   ' Dock Schedule processed folder
    Dim olAtt As Object                     ' Outlook attachement
    Dim k As Long                           ' Index to folder item
    Dim FileName As String                  ' File names in folder
    
    Dim MailBox As String                   ' Labor Analysis mailbox
    Dim InFolder As String                  ' Dock Schedules folder in Outlook
    Dim SubFolder As String                 ' Processed folder in Outlook
    Dim ExcelFolder As String               ' Folder to which to download attachments
    Dim KeepFileTypes                       ' File Types to keep
    
    Const olMailItem As Long = 0
    
    ' Initalize variables
    MailBox = Range("MailBox")
    InFolder = Range("In_Folder")
    SubFolder = Range("Sub_Folder")
    ExcelFolder = Range("Excel_Folder")
    KeepFileTypes = Range("Keep_File_Types")
    KeepFiles = Split(KeepFileTypes, ",")
    
    
    ' Set up mailbox
    Set olApp = CreateObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")
    Set FldrIn = olNS.Folders(MailBox).Folders("Inbox").Folders(InFolder)
    DoEvents
    Set FldrOut = olNS.Folders(MailBox).Folders("Inbox").Folders(InFolder).Folders(SubFolder)
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    ' Go through mail items bottom to top
    For k = FldrIn.Items.Count To 1 Step -1
        DoEvents
        Application.StatusBar = FldrIn.Items(k).Subject
        ' Get all attachments in the downloaded email
        For Each olAtt In FldrIn.Items(k).Attachments
            DoEvents
            ' Load them to the Excel Directory if they are "keepers"
            For kf = 0 To UBound(KeepFiles)
                If KeepFile(olAtt.FileName) = True Then
                    olAtt.SaveAsFile ExcelFolder & "\" & olAtt.FileName
                    DoEvents
                    Exit For
                End If
            Next kf
        Next olAtt
    
        ' Move the message to the Processed folder and mark it as read
        FldrIn.Items(k).UnRead = False
        FldrIn.Items(k).Move FldrOut
        DoEvents
    Next k
    
    ' Clean up Outlook
    Set FldrIn = Nothing
    Set olNS = Nothing
    Set olApp = Nothing
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    Application.StatusBar = False
    
    End Sub
    
    Function KeepFile(AttachString As String) As Boolean
    For kf = 0 To UBound(KeepFiles)
        If AttachString Like KeepFiles(kf) Then
            KeepFile = True
            Exit Function
        End If
    Next kf
    KeepFile = False
    End Function
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor
    Join Date
    03-08-2011
    Location
    Lubbock, TX, USA
    MS-Off Ver
    MS OFFICE 365 EXCEL, OUTLOOK, WORD, POWERPOINT
    Posts
    196

    Re: Saving attachments in multiple emails in outlook 365

    That looks like just the ticket. Thank You.

+ 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. [SOLVED] Outlook emails pulling attachments from Sharepoint
    By Seth_ in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-01-2019, 07:33 AM
  2. Macros to send multiple attachments to multiple emails in Outlook
    By melvern28 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-27-2018, 07:44 AM
  3. [SOLVED] Excel Macro to Send Multiple Emails w/ Attachments using MS Outlook 2007
    By arnel_10 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-17-2017, 08:09 PM
  4. Send multiple emails with different attachments if attachments found
    By AnkitJain in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2015, 05:35 AM
  5. Macro to Print all attachments across multiple emails in Outlook folder then delete email
    By Melissa Camp in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2015, 05:45 PM
  6. Accessing Outlook Attachments from Saved Emails
    By crunchKH in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2013, 12:38 AM

Tags for this Thread

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