VBA在单元格日期输入更改时发送电子邮件

问题描述:

我遇到此编码问题。我想它的代码,这样的邮件将自动发送当进入在某个表上列B中的日期VBA在单元格日期输入更改时发送电子邮件

基本上什么事情发生的是,员工将获得新的日常任务。日期会根据输入的日期更改。

我会喜欢它,如果代码将承认已输入当前日期和发送电子邮件给特定员工。这里有一个示例代码,但它只设置为数值,我不知道如何更改它。请帮忙!

此代码位于特定工作表中。

Private Sub Worksheet_Change(ByVal Target As Range) 
    If Target.Cells.count > 1 Then Exit Sub 
    If Not Application.Intersect(Range("A:A"), Target) Is Nothing Then 
     If IsNumeric(Target.Value) And Target.Value >= 1 Then 
      Call Send_Email 
     End If 
    End If 
End Sub 

这一代码进入模块

Sub Send_Email() 
     Dim OutApp As Object 
     Dim OutMail As Object 
     Dim strbody As String 

    Set OutApp = CreateObject("Outlook.Application") 
    Set OutMail = OutApp.CreateItem(0) 

    strbody = "Hi All" & vbNewLine & vbNewLine & _ 
       "You may have new cases." & vbNewLine & _ 
       "Please review and disposition them." & vbNewLine & _ 
       "Thank you" 

    On Error Resume Next 
    With OutMail 
     .To = "Calheers Unit" 
     .CC = "" 
     .BCC = "" 
     .Subject = "New Case Assignments" 
     .Body = strbody 
     .Send 
    End With 
    On Error GoTo 0 

    Set OutMail = Nothing 
    Set OutApp = Nothing 
End Sub 
+0

日期会根据输入的日期而改变是什么意思?我们如何找到正确的员工发送电子邮件? – cronos2546 2014-11-20 23:50:51

如果您要检查如果今天输入的日期只是检查是否target.value等于日期英寸日期代表VBA今天的日期一样= TODAY()在Excel中。

Private Sub Worksheet_Change(ByVal Target As Range) 
    If Target.Cells.Count > 1 Then Exit Sub 
    If Target.Column = 2 Then    'If target is in column B 
     If Target.Value = Date Then   'If the target value is today 
      Call Send_Email 
     End If 
    End If 
End Sub 
+0

是的,这完美地工作!非常感谢! – Lillian 2014-11-21 17:05:50