2015-05-15 14 views
-2

我傾向於做的是我有一個Excel表和工作人員名單,我想發送一個Excel表單提醒。我試圖用DefferdDeliverytime選項發送電子郵件,將電子郵件停放在發件箱中,並在稍後發送。使用此代碼,我可以發送消息,但是我不知道如何執行的操作是,根據Excel表添加代碼以發送特定的發送時間併發送電子郵件。任何人都可以添加一個代碼讓我工作。VBA發送不同時間的大量郵件

Sub Mail_To_Friends() 
    'Below Loop can be changed to While Loop or increase the limit (10) if your list has more than 10 mail ids 
    Dim SendTo As String 
    Dim ToMSg As String 
    Dim DueDate As String 
    Dim AwardN As String 
    Dim SendTime As String 

    For i = 2 To 10 
     SendTo = ThisWorkbook.Sheets(1).Cells(i, 22) 
     If SendTo <> "" Then 
      ToMSg = ThisWorkbook.Sheets(1).Cells(i, 15) 
      DueDate = ThisWorkbook.Sheets(1).Cells(i, 14) 
      AwardN = ThisWorkbook.Sheets(1).Cells(i, 1) 
      SendTime = ThisWorkbook.Sheets(1).Cells(i, 22) 
      Send_Mail SendTo, ToMSg, DueDate, AwardN, SendTime 
     End If 
    Next i 
End Sub 
Sub Send_Mail(SendTo As String, ToMSg As String, DueDate As String, AwardN As String, SendTime As String) 
    Dim OutlookApp As Object 
    Dim OutlookMail As Object 

    Set OutlookApp = CreateObject("Outlook.Application") 
    Set OutlookMail = OutlookApp.CreateItem(0) 

    With OutlookMail 
     .To = SendTo 
     .CC = "" 
     .BCC = "" 
     .Subject = "draft report is due" 
     .Body = "Dear " & ToMSg & vbNewLine & vbNewLine & "The following report is due to member on " & DueDate & vbNewLine & vbNewLine & "Award Name: " & AwardN 
     .Display 'or just put .Send to directly send the mail instead of display 
    End With 

    Set OutlookMail = Nothing 
    Set OutlookApp = Nothing 
End Sub 
+2

您必須更準確地描述您遇到的問題。 – byako

+0

我已更新我的問題 –

回答

1

這與在MailItem上設置DeferredDeliveryTime屬性一樣簡單。

With OutlookMail 
    .To = SendTo 
    .DeferredDeliveryTime = SendTime 
    '... insert rest of your code here 
End With 

有幾點要記住;首先這個屬性是一個DateTime,你的SendTime是一個String。它應該接受這假設它是在一個有效的格式,即。 18/05/2015。如果您不指定時間,則默認爲00:00:00。其次,這將使您的發件箱中的項目保留在本地PC上。因此,您必須打開Outlook才能在指定的時間發送電子郵件。

+0

嗨,非常感謝您的回答。有一個錯誤說。運行時錯誤440該對象不支持此方法。將調試點指向「.DeferredDeliveryTime = SendTime」 –

+0

您可以舉一個SendTime變量中傳遞的數據的例子嗎? – andshrew

+0

這是什麼在2015年5月19日3:00:00 PM請查看文件的鏈接https://drive.google.com/file/d/0B97BzUn3O6m6OUV2cXZBVm5TSDg/view?usp=sharing –