NotaVBAeXpert
New Member
- Joined
- May 4, 2018
- Messages
- 26
Hi All,
I want to automatically download attachments I receive from work to a folder on my computer. Currently, I have it downloading everything in my inbox but I want to set parameters so it only downloads the prior weeks attachments from the current day. This is what I have so far:
Option Explicit
Sub GetAttachments()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0
If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, _
"Nothing Found"
End If
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = "C:\Users\Documents" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the C:\Users\Documents\." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, _
"Finished!"
End If
End Sub
Does anyone have any ideas on how to set those parameters and only look back a week?
Thanks!
I want to automatically download attachments I receive from work to a folder on my computer. Currently, I have it downloading everything in my inbox but I want to set parameters so it only downloads the prior weeks attachments from the current day. This is what I have so far:
Option Explicit
Sub GetAttachments()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0
If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, _
"Nothing Found"
End If
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = "C:\Users\Documents" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the C:\Users\Documents\." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, _
"Finished!"
End If
End Sub
Does anyone have any ideas on how to set those parameters and only look back a week?
Thanks!