从今天起发送电子邮件

时间:2019-06-19 19:13:23

标签: excel vba excel-formula outlook

我有一个用于许可的excel电子表格,其中一栏是其失效日期。我的老板希望收到有关在接下来的两周内到期的许可证的电子邮件。每次打开Excel电子表格时,我如何使用Visual Basic告诉Outlook发送电子邮件?

这是我设置的电子表格,允许名称在A列中,日期在J列中。

Sub Mail_small_Text_Outlook()
Dim OutMail As Object
Dim strbody As String

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

strbody = "Hi there" & vbNewLine & vbNewLine & _
          "Cell A1 is changed" & vbNewLine & _
          "This is line 2" & vbNewLine & _
          "This is line 3" & vbNewLine & _
          "This is line 4"

On Error Resume Next
With OutMail
    .To = "ron@debruin.nl"
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .Body = strbody
    'You can add a file like this
    '.Attachments.Add ("C:\test.txt")
    .Display   'or use .Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Sub

我可能必须使用按钮来运行程序,但是我不确定是否可以安排电子邮件。

2 个答案:

答案 0 :(得分:0)

您似乎没有将OutApp调暗为对象。

完成后,添加一个循环,检查到期日期并将特定的单元格添加到动态数组中,并在每次迭代时对数组进行重新调暗。最后,阵列上的每个许可证都需要添加到文本字符串,然后可以将其添加到上面创建的电子邮件的正文中。...

完成上述所有操作后,您将希望将整个操作与Workbook Open事件联系起来。

答案 1 :(得分:0)

在VBE中,打开“本工作簿” ...

然后使用下拉菜单选择“工作簿”和“打开事件”,然后添加代码并保存。

enter image description here

相关问题