我目前有将基于未来到期日的电子邮件中的代码。下面是我的表的例子。 [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
要获得ID号在邮件正文中,见例如
Dim x As Long
Dim Sht As Worksheet
Set Sht = ThisWorkbook.Sheets("Sheet2")
Dim lastrow As Long
With Sht
lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
.Cells(x, 37).Value = mydate2
Set myApp = New Outlook.Application
Set mymail = myApp.CreateItem(olMailItem)
Dim IDnumber As String
IDnumber = .Cells(x, 1).Value
Debug.Print IDnumber ' print on immediate Window
With mymail
.Subject = "Payment Reminder"
.Body = "ID Number " & IDnumber
.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
Next
我想创造什么,我想在Excel中,然后再将其导入。
SubjectTemp = wb.names("NamedRange!").Referstorange.value2
--
With mymail
.Subject = SubjectTemp
.Body = "Please close your ICAR by due date"
.Display
'.send
End With
--
="My email subject is to "&$A$1
这台主题为“我的电子邮件的主题是”和无论是在A1。
冲洗和重复的所有领域。
它允许的Excel方便编辑里面,而不需要进入VBA。