Download & Move Attachments

Status
Not open for further replies.

zmagic

Member
Outlook version
Outlook 2013 32 bit
Email Account
IMAP
Hi,

With this script i am already downloading and saving the particular files to my hard drive, now i have some more attachment to be downloaded but i want them to be saved to different folder on my hard drive, Help me to do this which will ease my work of moving files from one place to another. File name is COJ12991 to D:\Soft

Code:
Sub GetAttachments_From_Inbox()   
   On Error GoTo GetAttachments_err
   Dim appOl As New Outlook.Application
   Dim ns As Outlook.NameSpace
   Dim Inbox As Outlook.MAPIFolder
   Dim myDestFolder As Outlook.MAPIFolder
   Dim Item As Object
   Dim Atmt As Outlook.Attachment
   Dim FileName As String
   Dim i As Integer
   Dim iLoop As Integer
   Dim sender As String
   Dim bankName As String
   Dim ext As String
   Dim Items As Outlook.Items
   Dim oc As Object
   Dim moveEmail As Boolean
   Set ns = appOl.GetNamespace("MAPI")
   Set Inbox = ns.GetDefaultFolder(olFolderInbox)
   Set Item = Inbox.Items
   Set myDestFolder = Inbox.Folders("Personal Mail")
   i = 0
   iLoop = 0
   If Inbox.Items.Count = 0 Then 
 
'       ' MsgBox "There are no messages in the Inbox.", vbInformation, _
       "Nothing Found"
       Exit Sub
   End If
   For iLoop = 1 To Inbox.Items.Count
       For Each Item In Inbox.Items
           moveEmail = False
           For Each Atmt In Item.Attachments
                If UCase(Atmt.FileName) Like "Export*" Or _
               UCase(Atmt.FileName) Like "Report*" Or _
               UCase(Atmt.FileName) Like "Update" Or _
               UCase(Atmt.FileName) Like "Sales*" Or _
        FileName = "D:\Attachments\" & Atmt.FileName
                   Atmt.SaveAsFile FileName
                   moveEmail = True
                   i = i + 1
               End If
           Next Atmt
           If moveEmail Then
               Item.Move myDestFolder
           End If
       Next Item
       iLoop = iLoop + 1
   Next   
        If i > 0 Then
       'MsgBox "I found " & i & " attached files." _
       & vbCrLf & "I have saved them into the D:\Attachments 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
   Set appOl = 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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R Re-download past messages Using Outlook 3
Rupert Dragwater Contact list didn't download Using Outlook 9
chummy Open multiple Hyperlinks to download files Outlook VBA and Custom Forms 3
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
B Outlook config download Outlook VBA and Custom Forms 1
H Free Malwarebytes Download - 1510-370-1986 Outlook VBA and Custom Forms 1
K Outlook Office 365 VBA download attachment Outlook VBA and Custom Forms 2
GregS Outlook 2016 iPhone won't download Outlook 2016 Mail. Using Outlook 0
O Office 365 Outlook - mark to download Using Outlook 0
G Download pdf attachments only if email subject has one of words Outlook VBA and Custom Forms 8
K Outlook 2010 duplicate download emails 1 inbox 1 PST no updates Using Outlook 3
R Would creating a new profile cause Outlook to download all the old mails from the server? Using Outlook 1
M Macro for attachments download adjustment Outlook VBA and Custom Forms 3
S Outlook 2013 doesn't download html messages Using Outlook 0
M Google Apps Mail *SENT* from iPhone doesn't download to Outlook via POP3 Using Outlook 1
P Email Download Outlook VBA and Custom Forms 12
C bcm 2010 download does not recognize outlook Using Outlook 3
RBLampert Outlook downloads error out if one particular account is the first to download Using Outlook 0
B Automatic picture download and changing email addresses Using Outlook 3
rezazy Do not download old email Using Outlook 1
D How to force full message download for all Gmail messages in all folders with IMAP in Outlook 2013 Using Outlook 1
V IMAP - download headers only Using Outlook 4
D VBA script to auto download attachments and rename file according to subject line Outlook VBA and Custom Forms 23
G Outlook 2013 won't download images Using Outlook 6
L Download/export multiple POP accounts Using Outlook 1
A Outlook doesnt download emails after reinstalling Using Outlook 4
T Unable to download e-mail sub account in OL 2010. No probs with Mailwasher Using Outlook 6
R Outlook download will not complete. Using Outlook 1
R Outlook Connector will not download ALL messages from hotmail accounts Using Outlook.com accounts in Outlook 4
S Outlook doesn't download all hotmail emails on Vista Using Outlook 2
K Download emails to HD Using Outlook 1
N Configure Outlook 2010 to download sent emails Using Outlook 4
Forum Admin Download BCM 2010 BCM (Business Contact Manager) 0
D Is It Possible To Download Contact Mngr Via a Website? BCM (Business Contact Manager) 1
P Download BCM Database BCM (Business Contact Manager) 1
R Auto Download Document Outlook VBA and Custom Forms 2
P How Do I Download Business Contact Manager BCM (Business Contact Manager) 1
P Download for KB957324 BCM (Business Contact Manager) 13
H Move Selected emails to Local Drive Outlook VBA and Custom Forms 0
A Search folder and move the email Outlook VBA and Custom Forms 0
A Outlook 365 (OutLook For Mac)Move "On My Computer" Folder Items From Old To New Mac Computer Using Outlook 4
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
humility36 Cannot move emails to archive - 440 error Outlook VBA and Custom Forms 1
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
C Trying to move messages between imap accounts/folders Using Outlook 5
M Move command Outlook VBA and Custom Forms 11
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
B Move emails from one account to another Outlook VBA and Custom Forms 2
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
N How to add or delete items to Move dropdown Menu Using Outlook 0

Similar threads

Back
Top