ファイル名が異なるさまざまな人に、1日に約100通のメールを送信する必要があります。以下のコードは問題なく動作しますが、問題は、添付する必要があるファイルの日付が 1 日前である必要があることです。たとえば、今日の日付は 2013 年 3 月 7 日 (7-03-13) です。ファイル RN2425 06-03-13.xls を取得し、これらは毎日変更されます。特定のディレクトリ D:\Reporting\Daily\RN2425\RN2425 (1 日前の日付スタンプ).xls で 1 日前のファイルを検索したい
ファイル名の日付を変更する必要があるこのコードを使用して助けてください。これを自動で行いたい。
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