我得到了一个要求,通过excel使后续工作通过自动化进行,提醒电子邮件需要通过VBA脚本发送。我获得了所有信息,但通过单击Excel工作簿中的命令按钮发送自动电子邮件会引发错误。请帮我在这发送提醒跟进时,在Excel中使用VBA的截止日期接近
Sub SendReminderMail()
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim iCounter As Integer
Dim MailDest As String
Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
With OutLookMailItem
MailDest = ""
For iCounter = 1 To WorksheetFunction.CountA(Columns(13))
If MailDest = "" And Cells(iCounter, 13).Offset(0, -1) = "Send Reminder" Then
MailDest = Cells(iCounter, 13).Value
ElseIf MailDest <> "" And Cells(iCounter, 13).Offset(0, -1) = "Send Reminder" Then
MailDest = MailDest & ";" & Cells(iCounter, 13).Value
End If
Next iCounter
.BCC = MailDest
.Subject = "Due date approaching"
.Body = "Reminder: Your due date is near approaching . Please ignore if already paid."
.Send
End With
Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
End Sub
我已经修改了我的剧本,因为这
Sub datesexcelvba()
Dim myApp, mymail
Dim mydate1 As Date
Dim mydate2 As Long
Dim datetoday1 As Date
Dim datetoday2 As Long
Dim x As Long
lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
mydate1 = Cells(x, 6).Value
mydate2 = mydate1
Cells(x, 9).Value = mydate2
datetoday1 = Date
datetoday2 = datetoday1
Cells(x, 10).Value = datetoday2
If mydate2 - datetoday2 = 3 Then
Set myApp = CreateObject(Outlook.Application)
Set mymail = myApp.CreateItem(olMailItem)
mymail.To = Cells(x, 5).Value
With mymail
.Subject = "Payment Reminder"
.Body = "Your credit card payment is due." & vbCrLf & "Kindly ignore if already paid." & vbCrLf & "Dinesh Takyar"
.Display
‘.Send
End With
Cells(x, 7) = "Yes"
Cells(x, 7).Interior.ColorIndex = 3
Cells(x, 7).Font.ColorIndex = 2
Cells(x, 7).Font.Bold = True
Cells(x, 8).Value = mydate2 - datetoday2
End If
Next
Set myApp = Nothing
Set mymail = Nothing
End Sub
这表明没有错误,但因为我无法发送电子邮件。我也在VB工具 - >参考 - > Microsoft Outlook 12.0对象库中进行了检查,但它不起作用。请帮助
我敢肯定,您无法发送邮件项目到多个.BCC收件人,而没有至少一个.To。将自己设置为.To。 – Jeeped
请帮助我如何做到这一点。电子邮件收件人被添加到工作表中,并且需要检查该单元并相应地发送电子邮件 –
您知道什么部分或哪部分代码以及哪些部分有问题? – Jeeped