【问题标题】:Send an email, if a cell in Excel has a specific date如果 Excel 中的单元格具有特定日期,请发送电子邮件
【发布时间】:2018-03-10 07:29:01
【问题描述】:
  1. Excel 将有一个不同日期的列表以及每个日期的收件人电子邮件 ID。
  2. 如果单元格有特定日期,则会向其中提到的电子邮件 ID 发送一封自动电子邮件。
  3. 邮件将通过 Outlook 发送。

【问题讨论】:

  • 分享您的代码尝试是吸引其他希望帮助您改进代码的用户的好方法。我们不是无代码社区。​​span>

标签: excel vba


【解决方案1】:

很笼统的问题,但让我们先谈谈可能的方法。 1. 循环从单元格中获取日期 2. 如果日期与特定日期匹配,则调用 sub 发送邮件 3.在sendMail方法的参数中传递对应的邮件id来发送邮件

我无法为您提供确切的代码,但大致如下:

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

【讨论】:

    猜你喜欢
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    相关资源
    最近更新 更多