+ Reply to Thread
Results 1 to 1 of 1

Macro to save attachments from an outlook shared inbox to a drive location

Hybrid View

Johnners Macro to save attachments... 11-20-2019, 01:08 PM
  1. #1
    Registered User
    Join Date
    11-20-2019
    Location
    London
    MS-Off Ver
    Office 365Proplus 1908
    Posts
    1

    Macro to save attachments from an outlook shared inbox to a drive location

    Hi,

    I recently found a macro that I run from within Outlook to save attachments to a disk from messages I highlight before I run the outlook macro. Works well and saves me ages but I was wondering if such a macro can be extended to do the following:

    1/ When triggered highlight all the messages in the shared inbox automatically so I do not have to do this manually.

    2/ Be triggered via an button on an Excel workbook taking some parameters such as location to save the files from cells on the worksheet.

    Here is the macro:
    Public Sub SaveAttachments_M()
    Dim objOL As Outlook.Application
    Dim objMsg As Outlook.MailItem 'Object
    Dim objAttachments As Outlook.Attachments
    Dim objSelection As Outlook.Selection
    Dim i As Long
    Dim lngCount As Long
    Dim StrFile As String
    Dim StrFolderPath As String
    Dim strDeletedFiles As String
    Dim dateFormat
    
    StrFolderPath = BrowseForFolder & "\"
    
    ' Get the path to your My Documents folder
    On Error Resume Next
    
    ' Instantiate an Outlook Application object.
    Set objOL = CreateObject("Outlook.Application")
    
    ' Get the collection of selected objects.
    Set objSelection = objOL.ActiveExplorer.Selection
    
    ' Set the Attachment folder.
    'strFolderpath = "C:\Temp\M\"
    
    
    ' Check each selected item for attachments. If attachments exist,
    ' save them to the strFolderPath folder and strip them from the item.
    For Each objMsg In objSelection
    
        ' This code only strips attachments from mail items.
        ' If objMsg.class=olMail Then
        ' Get the Attachments collection of the item.
        Set objAttachments = objMsg.Attachments
        dateFormat = Format(objMsg.ReceivedTime, "ddmmyy-hhmmss")
        lngCount = objAttachments.Count
        strDeletedFiles = ""
    
        If lngCount > 0 Then
    
            ' We need to use a count down loop for removing items
            ' from a collection. Otherwise, the loop counter gets
            ' confused and only every other item is removed.
    
            For i = lngCount To 1 Step -1
    
                ' Save attachment before deleting from item.
                ' Get the file name.
                StrFile = objAttachments.Item(i).FileName
    
                ' Combine with the path to the Temp folder.
                If Left(StrFile, 4) = "MITA" And Mid(StrFile, 10, 3) <> "_AR" Then
                    If Right(StrFile, 3) = "xls" Then
                        StrFile = StrFolderPath & Left(StrFile, 9) & "-" & dateFormat & Right(StrFile, 4)
                    Else: StrFile = StrFolderPath & Left(StrFile, 9) & "-" & dateFormat & Right(StrFile, 5)
                    End If
                ElseIf Mid(StrFile, 10, 3) <> "_AR" Then
                    StrFile = StrFolderPath & StrFile
                End If
    
                ' Save the attachment as a file.
                objAttachments.Item(i).SaveAsFile StrFile
            
            Next i
           
        End If
    Next
    
    ExitSub:
    
    Set objAttachments = Nothing
    Set objMsg = Nothing
    Set objSelection = Nothing
    Set objOL = Nothing
    Last edited by davesexcel; 11-20-2019 at 01:34 PM.

+ 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] Macro to save file in shared network drive
    By Dscalf1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2019, 02:38 AM
  2. Add Shared Outlook Inbox
    By stimulus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-03-2017, 09:20 AM
  3. VBA to extract attachment from Inbox/Sub_folder to Drive path In outlook
    By julielara in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 07-28-2016, 03:22 PM
  4. Create outlook task from shared inbox in VBA
    By trmtt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2015, 11:44 AM
  5. Need a help to extract inbox mails and save in D: drive with sender name
    By Jack40 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2014, 02:28 PM
  6. Replies: 0
    Last Post: 09-12-2013, 07:43 AM
  7. Can't sweep shared MS Outlook Inbox for attachments?
    By dt99 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-21-2013, 08:54 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