如何根据值自动发送电子邮件并使其根据日期发送电子邮件?

时间:2017-08-10 19:52:07

标签: vba excel-vba email excel

这是代码: 目前我有一个电子表格,如果表中的值超过200,我会发送电子邮件,我想这样做,以便它会在9天之前发送一封提示电子邮件,说“你有一个截止于星期三的节目”,还有一个说“你有一个节目将于本周三“前2天到期。任何帮助表示赞赏!

Option Explicit

Private Sub Worksheet_Calculate()
    Dim FormulaRange As Range
    Dim NotSentMsg As String
    Dim MyMsg As String
    Dim SentMsg As String
    Dim MyLimit As Double

    NotSentMsg = "Not Sent"
    SentMsg = "Sent"

    'Above the MyLimit value it will run the macro
    MyLimit = 200

    'Set the range with Formulas that you want to check
    Set FormulaRange = Me.Range("B3:B7")

    On Error GoTo EndMacro:
    For Each FormulaCell In FormulaRange.Cells
        With FormulaCell
            If IsNumeric(.Value) = False Then
                MyMsg = "Not numeric"
            Else
                If .Value > MyLimit Then
                    MyMsg = SentMsg
                    If .Offset(0, 1).Value = NotSentMsg Then
                        Call Mail_with_outlook2
                    End If
                Else
                    MyMsg = NotSentMsg
                End If
            End If
            Application.EnableEvents = False
            .Offset(0, 1).Value = MyMsg
            Application.EnableEvents = True
        End With
    Next FormulaCell

ExitMacro:
    Exit Sub

EndMacro:
    Application.EnableEvents = True

    MsgBox "Some Error occurred." _
         & vbLf & Err.Number _
         & vbLf & Err.Description

End Sub

0 个答案:

没有答案