Outlook VBA Attachment Download Help

moni_tm

New Member
Joined
Nov 4, 2015
Messages
29
Hi,

I have a code in VBA that downloads my Outlook attachments but id like to update if possible.

Here is the current code.

Code:
Public Sub SaveAttachmentsToDiskOperaCorrection(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\tmona623\Desktop\Cash Dec\AutoDownload\Opera Reports\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & Format(Date, "DD-MM-YY") & " " & MItem.SenderEmailAddress & " " & oAttachment.DisplayName
Next
End Sub

I'd like to change the following bit if possible.

Code:
& Format(Date, "DD-MM-YY")
Can this be changed so that it generates the previous day?

Code:
& MItem.SenderEmailAddress
Can this be changed so that it only grabs the first 5 letters of the e-mail address?


Any help is greatly appreciated.

Tom
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Totally untested....

Code:
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & Format(Date - 1, "DD-MM-YY") & " " & Left(MItem.SenderEmailAddress, 5) & " " & oAttachment.DisplayName
Next
 
Upvote 0
Hi Thanks for that, it works, is it possible to change the date part to timestamp from when it arrived in Outlook?


-- removed inline image ---


Thank you

Tom
 
Upvote 0
You can try but untested...

Code:
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & Format(MItem.ReceivedTime, "DD-MM-YY") & " " & Left(MItem.SenderEmailAddress, 5) & " " & oAttachment.DisplayName
Next
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top