发送带有基于条件的结果的电子邮件

时间:2018-09-06 13:25:05

标签: excel excel-vba

我有一份每天根据客户付款生成的报告。如果付款超过1万美元,则会自动生成一封电子邮件并将其发送给相关方。我有2个根据商家生成的不同电子邮件(下面列出的代码)。我的问题是,目前的书写方式是,每次付款都会发送一封电子邮件,因此,如果我尝试为一位商人发送3笔付款,则它们将以3封电子邮件发送出去。我如何将其压缩为每位商家的一封电子邮件,而不管每位商家1万美元以上的支付金额为何?

public void dumpRequest(HttpServletRequest request) {

    String[] attrNames = new String[100]; // hard coded
    int ani = 0;

    Enumeration rns = request.getAttributeNames();
    while (rns.hasMoreElements()) {
        out.println("attribute name: " + rns.nextElement());
        attrNames[ani] = rns.nextElement().toString();
        ani = ani + 1;
    }

    out.println("" + ani + " atributes");
    String cn;
    for (int n = 0; n < ani; n++) {
        cn = attrNames[n];
        out.println("** " + cn + " - " + request.getAttribute(cn));
    }
    out.println("++++++++++++++++++++++");

}

我曾考虑过将Public Sub Over10k() Dim ws1 As Worksheet Dim row As Long Dim OutLookApp As Object Dim OutLookMailItem As Object Dim tDay As String If Format(Now(), "hh:mm:ss") >= "12:00:00" Then tDay = "Afternoon" Else tDay = "Morning" End If Set ws1 = Worksheets("Summary") Set OutLookApp = CreateObject("Outlook.application") Set OutLookMailItem = OutLookApp.CreateItem(0) row = 3 Do Until Trim$(Cells(row, "A").Value) = "" If ws1.Cells(row, "D") = "###" And ws1.Cells(row, "J") >= 10000 Then Set OutLookMailItem = OutLookApp.CreateItem(0) With OutLookMailItem .To = "<some people>" .CC = "<some other people>" .Subject = "In-Store Payment Over $10k - <Merchant 1>" .Display .HTMLBody = "<BODY style=font-size:11pt;font-family:Cambria>Good " & tDay & ", " & "<br>" & "<br>" & _ "Please note the following payment(s) made in-store on " & Format(ws1.Cells(row, "E"), "m/d/yyyy") & ":" _ & "<br>" & ws1.Cells(row, "A") & ", " & ws1.Cells(row, "C") & ", " & ws1.Cells(row, "G") _ & ", " & Format(ws1.Cells(row, "J"), "currency") & "</BODY>" & .HTMLBody .Send End With End If row = row + 1 Loop row = 3 Do Until Trim$(Cells(row, "A").Value) = "" If ws1.Cells(row, "D") <> "###" And ws1.Cells(row, "J") >= 10000 Then Set OutLookMailItem = OutLookApp.CreateItem(0) With OutLookMailItem .To = "<some people>" .CC = "<some other people>" .Subject = "In-Store Payment Over $10k - <merchant 2>" .Display .HTMLBody = "<BODY style=font-size:11pt;font-family:Cambria>Good " & tDay & ", " & "<br>" & "<br>" & _ "Please note the following payment(s) made in-store on " & Format(ws1.Cells(row, "E"), "m/d/yyyy") & ":" _ & "<br>" & ws1.Cells(row, "A") & ", " & ws1.Cells(row, "C") & ", " & ws1.Cells(row, "G") _ & ", " & Format(ws1.Cells(row, "J"), "currency") & "</BODY>" & .HTMLBody .Send End With End If row = row + 1 Loop End Sub 移到电子邮件正文中,但是即使没有符合条件的付款,我也会发送电子邮件。还是我可以在开始时添加一个额外的If来表示是否向If支付了$ 10,000以上的款项? TIA

0 个答案:

没有答案