我很难更改VBA代码,以使电子邮件内容中的静态日期变为动态。能否请您检查我的代码并让我知道我的错误?
此代码用于向一群人发送电子邮件。电子邮件中有一些日期,可能会定期更改。因此,我希望能够在Excel中更新一个单元格(L3),并自动更改电子邮件内容(包括标题)中的日期。
Sub Mail_small_Text_Change_Account()
Dim cel As Range
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("D").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
Cells(cell.Row, "G") = "Y" Then
strbody = "Dear " & Cells(cell.Row, "C").Value _
& vbNewLine & vbNewLine & _
"Please confirm by" & Cells(cell.Row, "L3").Value _ & " so that we may be able to "
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.To = cell.Value
'.CC = cel.Offset(0, 3).Value
.Subject = "Action may be required by" & Cells(cell.Row, "L3").Value _
.Body = strbody
.SendUsingAccount = OutApp.Session.Accounts.Item(3)
.Display 'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub