无法在参考单元格中发送带有日期的电子邮件

时间:2019-05-28 14:21:59

标签: excel vba

我有一个代码,用于在特定单元格中输入值> 0时发送电子邮件。除将代码放在实际电子表格中无法执行之外,测试均已成功完成。我可以看到的唯一区别是,我使用电子表格中的日期作为触发器。使用日期时,我需要用不同的方式写吗?

Dim xRg As Range
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
  Set xRg = Intersect(Range("J13"), Target)
    If xRg Is Nothing Then Exit Sub
    If IsNumeric(Target.Value) And Target.Value > 0 Then
        Call Mail_small_Text_Outlook
    End If
End Sub
Sub Mail_small_Text_Outlook()
    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Hello" & vbNewLine & vbNewLine & _
              "This is to inform you that" & vbNewLine & _
              "This item requires your attention"
    On Error Resume Next
    With xOutMail
        .To = "Email Address"
        .CC = ""
        .BCC = ""
        .Subject = "send by cell value test"
        .Body = xMailBody
        .Display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

我希望可以在电子表格中每个客户分组的多行中使用此功能,以将自动通知发送给接触客户产品的下一个团队。

0 个答案:

没有答案