我有一张带有日期安排信息的Excel表格。我想每天发送有关每天安排的电话数和预约数的每日更新。电子表格如下所示:
Date Scheduled Called Notes
07/06/2015 0 5 None
07/07/2015 5 12 None
07/08/2015 2 10 None
我正在尝试编写一个程序,比如2015年7月6日,将生成一封电子邮件,其中包含当天的预定,电话和笔记,并自动发送。这可能吗?
答案 0 :(得分:6)
这是我认为可以成为一个坚实的开端。您显然必须解决邮件应发送到的电子邮件地址以及如何格式化正文等等。
给予r的范围是基于您提供的样本数据,它占用了A2-A4,但将其更改为正确的数据。
Option Explicit
Sub email()
Dim r As Range
Dim cell As Range
Set r = Range("A2:A4")
For Each cell In r
If cell.Value = Date Then
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "subject"
Email_Send_From = "bob@bob.com"
Email_Send_To = "bob@bob.com"
Email_Cc = "bob@bob.com"
Email_Bcc = "bob@bob.com"
Email_Body = "body"
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.cc = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.send
End With
End If
Next
Exit Sub
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub
答案 1 :(得分:0)
这有点晚,但对您和其他人有帮助:
使用以下代码创建VB脚本文件:(打开记事本,粘贴下面的代码,符合您的需要,另存为:vbscript文件)
Path="complete_file_path_of_your_excel_file.xlsm"
Macro="email"
Set objApp = CreateObject("Excel.Application.16")
objApp.Visible = True
Set wbToRun = objApp.Workbooks.Open(Path)
objApp.Run Macro
设置Windows任务计划程序,以便在特定时间每天打开您创建的VBscript文件。
您现在拥有一套“一劳永逸”的通知机器人。