我需要在一天内向具有不同文件名的不同人发送近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
答案 0 :(得分:2)
以正确的格式获取今天的日期:
获取昨天的日期:
全部放在一起: