Trying2learnVBA
Board Regular
- Joined
- Aug 21, 2019
- Messages
- 67
- Office Version
- 365
- 2021
- Platform
- Windows
Hello,
I have this code that works really well for automating repetitive emails from excel. However, I need to attach a file daily. So, the file's name changes daily.
How can I modify my code to always select the latest file?
Thank you for your help!!!
I have this code that works really well for automating repetitive emails from excel. However, I need to attach a file daily. So, the file's name changes daily.
How can I modify my code to always select the latest file?
VBA Code:
Sub CollRecon_Email()
Dim EApp As Object
Set EApp = CreateObject("Outlook.Application")
Dim EItem As Object
Set EItem = EApp.CreateItem(0)
Dim path As String
path = "K:\CapMkt\Collateral Recon\Findur Reports\Collateral Balances CSV\Collateral Cashflow Transaction Balance_20220824_1219026.csv" 'The name of this file changes daily - notice the "20220824" number is today's date. The last numbers are semi random. I'd like excel to grab the file modified Today's date.
Dim CL As Worksheet
Set CL = ThisWorkbook.Sheets("CONTACT LIST")
With EItem
.display
.To = "counterpartyrisk@tiaabank.com"
.Subject = "Collateral Recon " & CL.Range("C1")
.cc = "May.love@tiaabank.com; Wendy.burnes@tiaabank.com"
.Attachments.Add (path) 'Here I would like the file with today's date to be picked.
.HTMLBody = "Hello," & "<br><br>" & "Collateral Recon is good to go" & .HTMLBody
End With
Set EApp = Nothing
Set EItem = Nothing
End Sub
Thank you for your help!!!