发送来自多个偏移行的更改的单元格值的电子邮件

时间:2019-08-12 20:07:35

标签: excel vba

当我们的Excel跟踪仪表板中的多个偏移量行彼此相距9,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 IsDate(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 client is now Committed & Complete and ready for your attention" & vbNewLine & vbNewLine & _
              "Renew As Is?" & vbNewLine & _
              "Adding Changing Groups?"                        
    On Error Resume Next
    With xOutMail
        .To = "abc@xyz.com;IDCardTeam@xyz.com"
        .CC = ""
        .BCC = ""
        .Subject = "Committed & Complete" & "  " & Range("B9").Value & "  " & Range("C9").Value
        .Body = xMailBody
        .Display   'or use .Send
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
End Sub

我需要工作表在目标单元格输入日期时发送电子邮件,并获取相关的cusotmer信息以填充电子邮件。

1 个答案:

答案 0 :(得分:0)

我不太清楚Mail子目录在哪里指向目标或偏移量,但是请尝试以下操作:

编辑:出于完整性考虑,这是经过测试的代码

$arr = [10 ,20 ,20 ,10, 10, 30, 50, 10, 20];

$counts = array_count_values($arr);

foreach($counts as $val => &$count){
    $count = floor($count/2);
}

var_dump($counts);


/*
array(4) {
  [10]=>
  float(2)
  [20]=>
  float(1)
  [30]=>
  float(0)
  [50]=>
  &float(0)
}
*/