从某个日期开始每14天发送邮件提醒

  • 本文关键字:14天 日期 开始 excel vba
  • 更新时间 :
  • 英文 :


下午好。我在Excel文件中使用VBA代码,并希望额外的代码行发送一个经常性的电子邮件提醒,如果文件没有保存在14天内。以下是我使用的代码。我已经搜索,但没有发现额外的代码来完成我所追求的。提前感谢您的专业知识和帮助。子SEND_Colleague ()

Dim MyFile As String
MyFile = ActiveWorkbook.Name
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= & MyFile
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
On Error Resume Next
On Error GoTo 0
With OutlookMail
.to = "JaneDoe@mail.com"
.Importance = 2
.Subject = ActiveWorkbook.Name
If InStr(Filename, ".") > 0 Then
End If
.HTMLbody = "<html><body><p><font size=4>My Colleague: <p></p>" _
& "</p><p>Please navigate to the tracking log named in the subject line of this email by clicking the link below and update the <b><i>Product</i></b> section of the log. <p></p>" _
& "Once your updates are entered, click the form control button in <b>Cell B61</b>. The workbook will be saved to the Network shared folder and closed automatically.  Thereafter, the Outlook mail program will be initiated and a pop-up warning message will appear.  Click <u><b>Allow</b></u> and an email will be sent to the area leader.  A copy of the email can be found in your Outlook <i>Sent</i> folder.<p>" _
& "</p><p><b><FONT COLOR=red>Note, you must return to this log and follow the steps above every 14 days until all thrid-party claims are fully adjudicated. </p></b><FONT COLOR=black>" _
& "</p><p>Thank You</p>" _

.SEND
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
ActiveWorkbook.Close
End Sub

您需要检查最后编辑日期是否大于14天。

您可以使用ThisWorkbook.BuiltInDocumentProperties访问工作簿的信息,它将返回文件属性的集合。最后修改的日期索引应该是12。然后,存储文件最后修改日期的值:

Dim DateLastModified As Date
DateLastModified = ThisWorkbook.BuiltinDocumentProperties(12)

然后将该日期与今天的日期(如果您愿意,还有时间,因为ThisWorkbook.BuiltinDocumentProperties(12)也包含时间信息)进行比较。

最新更新