Ok, so I have an email with an attachment I receive everyday and it is automatically sent to an Outlook folder named "Voya".
What I want to do is write a macro where I can open the file from today's email only on a daily basis.
I tested this code and a file is saved to a folder on my desktop, but here are my questions:
1. How do I make this so it just opens instead of saves?
2 . This code doesn't specify a date or anything, so is it just extracting the attachment of the most recent email?
3. I see this code uses a "For Each OlMail In OlItem." Does that mean it is attempting to extract all the attachments from all the emails in that folder? Because if so, it only extracted one(like I want) and I have several, so I'm confused.
I'm sharing this code with others so I want to make sure it's written correctly. Any other feedback is appreciated.
Thanks.
Sub Download_test()
Dim OlApp As Object
Dim OlMail As Object
Dim OlItems As Object
Dim OlFolder As Object
Dim i As Integer
Dim strFolder As String
Set OlApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Set OlApp = CreateObject("Outlook.Application")
End If
strFolder = "...............\Desktop\New folder"
Set OlFolder = OlApp.GetNamespace("MAPI").Folders(MY_EMAIL).Folders("Voya")
Set OlItems = OlFolder.Items
For Each OlMail In OlItems
If OlMail.Attachments.Count > 0 Then
For j = 1 To OlMail.Attachments.Count
OlMail.Attachments.Item(j).SaveAsFile strFolder & "\" & OlMail.Attachments.Item(j).FileName
Next j
End If
Next
Set OlFolder = Nothing
Set OlItems = Nothing
Set OlMail = Nothing
Set OlApp = Nothing
End Sub
What I want to do is write a macro where I can open the file from today's email only on a daily basis.
I tested this code and a file is saved to a folder on my desktop, but here are my questions:
1. How do I make this so it just opens instead of saves?
2 . This code doesn't specify a date or anything, so is it just extracting the attachment of the most recent email?
3. I see this code uses a "For Each OlMail In OlItem." Does that mean it is attempting to extract all the attachments from all the emails in that folder? Because if so, it only extracted one(like I want) and I have several, so I'm confused.
I'm sharing this code with others so I want to make sure it's written correctly. Any other feedback is appreciated.
Thanks.
Sub Download_test()
Dim OlApp As Object
Dim OlMail As Object
Dim OlItems As Object
Dim OlFolder As Object
Dim i As Integer
Dim strFolder As String
Set OlApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Set OlApp = CreateObject("Outlook.Application")
End If
strFolder = "...............\Desktop\New folder"
Set OlFolder = OlApp.GetNamespace("MAPI").Folders(MY_EMAIL).Folders("Voya")
Set OlItems = OlFolder.Items
For Each OlMail In OlItems
If OlMail.Attachments.Count > 0 Then
For j = 1 To OlMail.Attachments.Count
OlMail.Attachments.Item(j).SaveAsFile strFolder & "\" & OlMail.Attachments.Item(j).FileName
Next j
End If
Next
Set OlFolder = Nothing
Set OlItems = Nothing
Set OlMail = Nothing
Set OlApp = Nothing
End Sub