I want to create code in excel that will look for a specific sender or subject from Outlook and copy the workbook attachment to a specific location on my desktop. I have no clue 1) if this is possible or 2) how to do it. I would also like to have it be a scheduled event that happens every Monday thru Friday.
I have this code currently but it only seems to work in outlook. Can I change this code to work in excel?
Sub SaveFile() Dim olApp As Outlook.Application Dim olNs As NameSpace Dim Fldr As MAPIFolder Dim MoveToFldr As MAPIFolder Dim olMi As MailItem Dim olAtt As Attachment Dim MyPath As String Dim i As Long Set olApp = New Outlook.Application Set olNs = olApp.GetNamespace("MAPI") Set Fldr = olNs.GetDefaultFolder(olFolderInbox) Set MoveToFldr = Fldr.Folders("DestinationFolder") MyPath = "C:\Users\daniel.white\Desktop\Destination Folder\" For i = Fldr.Items.Count To 1 Step -1 Set olMi = Fldr.Items(i) If InStr(1, olMi.Subject, "June2012 TDC Deliveries.xlsx") > 0 Then For Each olAtt In olMi.Attachments If olAtt.FileName = "June2012 TDC Deliveries.xlsx" Then olAtt.SaveAsFile MyPath & olMi.SenderName & ".xlsx" End If Next olAtt olMi.Save olMi.Move MoveToFldr End If Next i Set olAtt = Nothing Set olMi = Nothing Set Fldr = Nothing Set MoveToFldr = Nothing Set olNs = Nothing Set olApp = Nothing End Sub