0

我在更改 VBA 代码时遇到困难,以便电子邮件内容中的静态日期变为动态日期。能否请您查看我的代码并让我知道我的错误?

此代码用于向一组人发送电子邮件。在电子邮件中,有一些日期可能会定期更改。因此,我希望能够在 Excel 中更新 ONE CELL (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
4

0 回答 0