【发布时间】:2019-02-05 15:19:20
【问题描述】:
我目前有一个代码,可以根据即将到来的截止日期生成一封电子邮件。下面是我的表的例子。 [Excel 表格的图像][1] [1]:https://i.stack.imgur.com/lYhlD.png。我的代码用于填充电子邮件,但我想在电子邮件字段中说明 ID、描述、分配给和截止日期。有人可以帮忙吗?
Sub datesexcelvba()
Dim myApp As Outlook.Application, mymail As Outlook.MailItem
Dim mydate1 As Date
Dim mydate2 As Long
Dim datetoday1 As Date
Dim datetoday2 As Long
Dim x As Long
With Sheets("Sheet2")
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
mydate1 = Cells(x, 7).Value
mydate2 = mydate1
Cells(x, 37).Value = mydate2
datetoday1 = Date
datetoday2 = datetoday1
Cells(x, 36).Value = datetoday2
If mydate2 - datetoday2 = 10 Then
Set myApp = New Outlook.Application
Set mymail = myApp.CreateItem(olMailItem)
mymail.To = Cells(x, 31).Value
mymail.CC = Cells(x, 32).Value
With mymail
.Subject = "Payment Reminder"
.Body = "Please close your ICAR by due date"
.Display
'.send
End With
Cells(x, 33) = “Yes”
Cells(x, 33).Interior.ColorIndex = 3
Cells(x, 33).Font.ColorIndex = 2
Cells(x, 33).Font.Bold = True
Cells(x, 33).Value = mydate2 - datetoday2
End If
Next
Set myApp = Nothing
Set mymail = Nothing
End With
End Sub
【问题讨论】: