我需要在一天内向不同文件名的不同人发送近 100 封电子邮件。下面的代码工作得很好,但问题是我必须附加的文件应该是前一天的。例如,今天的日期是 2013 年 3 月 7 日 (7-03-13)。我得到文件 RN2425 06-03-13.xls,这些文件每天都在变化。我想在特定目录 D:\Reporting\Daily\RN2425\RN2425 (一天前的日期戳).xls 中查找前一天的文件
请使用此代码帮助我,我需要更改文件名中的日期。我希望这能自动完成。
Sub CreateEmail(Subject As String, Body As String, ToSend As String, CCs As String, FilePathtoAdd As String)
'write the default Outlook contact name list to the active worksheet
Dim OlApp As Object
Dim OlMail As MailItem
Dim ToRecipient As Variant
Dim CcRecipient As Variant
'Set OlApp = CreateObject("Outlook.Application")
'Set OlMail = OlApp.CreateItem(olMailItem)
Set OlApp = Application
Set OlMail = OlApp.CreateItem(olMailItem)
'For Each ToRecipient In Array("mba.szabist@gmail.com", "mba.szabist@gmail.com", "mba.szabist@gmail.com")
'OlMail.Recipients.Add ToRecipient
OlMail.Recipients.Add ToSend
'Next ToRecipient
'For Each CcRecipient In Array("happychords@yahoo.com", "happychords@yahoo.com", "happychords@yahoo.com")
'With OlMail.Recipients.Add(CcRecipient)
'.Type = 2
'End With
'Next CcRecipient
Dim Temp As Recipient
Set Temp = OlMail.Recipients.Add(CCs)
Temp.Type = olCC
'fill in Subject field
OlMail.Subject = Subject
OlMail.Body = Body
'Add the active workbook as an attachment
' OlMail.Attachments.Add "C:\Users\Ali\Desktop\Sentence Correction\Comparisons.pdf"
If FilePathtoAdd <> "" Then
OlMail.Attachments.Add FilePathtoAdd
End If
'Display the message
OlMail.Display 'change this to OlMail.Send if you just want to send it without previewing it
End Sub
Sub EmailIt()
CreateEmail "This is Subject", "Body", "kamran@yahoo.com, kamu@yahoo.com", "me@yahoo.com, my@yahoo.com", "E:\Ali's Documents\RN2425 06-03-13.xls"
CreateEmail "This is Subject", "Body", "kamran@yahoo.com, kamu@yahoo.com", "me@yahoo.com, my@yahoo.com", "E:\Ali's Documents\RN2425 06-03-13.xls"
CreateEmail "This is Subject", "Body", "kamran@yahoo.com, kamu@yahoo.com", "me@yahoo.com, my@yahoo.com", "E:\Ali's Documents\RN2425 06-03-13.xls"
CreateEmail "This is Subject", "Body", "kamran@yahoo.com, kamu@yahoo.com", "me@yahoo.com, my@yahoo.com", "E:\Ali's Documents\RN2425 06-03-13.xls"
CreateEmail "This is Subject", "Body", "kamran@yahoo.com, kamu@yahoo.com", "me@yahoo.com, my@yahoo.com", "E:\Ali's Documents\RN2425 06-03-13.xls"
CreateEmail "This is Subject", "Body", "kamran@yahoo.com, kamu@yahoo.com", "me@yahoo.com, my@yahoo.com", "E:\Ali's Documents\AVSEQ03 Comp 1.avi"
End Sub