2016-11-23 7 views
0
  1. Excelには、日付ごとに異なる受信者の電子メールIDのリストがあります。
  2. セルに特定の日付が設定されている場合、そのセルに記載されている電子メールIDに自動電子メールが送信されます。
  3. メールはOutlook経由で送信されます。
+3

コードの試行を共有すると、改善に役立つ他のユーザーを引き付ける良い方法です。私たちはcode4freeコミュニティではありません。 –

答えて

0

かなり一般的な質問ですが、まず可能なアプローチについてお話します。ループ 2の細胞から 1.取得日、特定の日付と日付の一致は、メールを送信するメールに(SendMailメソッドの)パラメータでメールIDに対応する 3.パスを送信するためにサブを呼び出す場合

I正確なコードを提供することはできませんが、おおよその方法は次のとおりです。

For i = 1 to n 
    strDate = workbooks.worksheet("Sheet1").cells(i,1) 
    emailList = workbooks.worksheet("Sheet1").cells(i,2) 
    if (strDate=expectedDate) then 
    call sendMail(emailList) 
    end if 
Next 


Public function sendMail(emailList) 

Dim OutApp As Object 
Dim OutMail As Object 

With Application 
    .ScreenUpdating = False 
    .EnableEvents = False 
End With 


On Error GoTo err 


'Now open a new mail 

Set OutApp = CreateObject("Outlook.Application") 
Set OutMail = OutApp.CreateItem(0) 

On Error Resume Next 
With OutMail 
.To = emailList 
.CC = "" 
.Subject = "test" 
.Body = "the content of the mail" 
End With 
On Error GoTo 0 


'set nothing to the objects created 
Set OutMail = Nothing 
Set OutApp = Nothing 

'Now set the application properties back to true 
With Application 
    .ScreenUpdating = True 
    .EnableEvents = True 
End With 
MsgBox ("Email has been Sent Successfully") 
Exit Sub 
err: 
    MsgBox err.Description 
End function 
関連する問題