2016-11-23 104 views
0
  1. Excel将在每个日期都有不同日期和接收者的电子邮件ID列表。
  2. 如果该单元格有特定日期,则会将自动电子邮件发送到其中提及的电子邮件ID。
  3. 邮件将通过Outlook发送。
+3

共享你的代码的尝试是为了吸引谁希望能帮助您在提高它的其他用户的好方法。我们不是一个code4free社区。 –

回答

0

相当普遍的问题,但让我们先来谈谈可能的方法。在一个循环中从细胞 1.获取日期 2.如果日期与特定日期相匹配,调用一个子发送邮件 3.通对应的邮件的ID参数(Sendmail的方法)来发送邮件

我将无法给你确切的代码,但在这里大致是怎么会:

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 
相关问题