Excel VBA电子邮件单元格值

时间:2016-10-11 09:07:51

标签: excel vba excel-vba email

我有以下代码,其中地址不起作用...我想知道如何从单元格中选择电子邮件地址值,因为使用单元格(1,1)。值它似乎不在我的案例中工作。

Sub email_missing_forecast()

Application.ScreenUpdating = False

'Déclaration des variables
derniereligne = Range("B").End(xlUp).Row
Adresse = Cells(i, "D").Value
Adresse2 = Cells(i, "E").Value
Adresse3 = Cells(i, "F").Value
Project_number = Cells(1, 2).Value
Project_name = Cells(2, 2).Value
Project_due = Cells(3, 2).Value
Lien = Cells(4, 2).Value


Dim Objoutlook As New Outlook.Application
Dim Objectmail

'Condition
For i = 6 To derniereligne
If Cells(i, "B").Value = "No" Then
    Set Objoutlook = New Outlook.Application
    Set Objectmail = Outlook.createitem(olmailitem)
        With Objectmail
        .To = Adresse & ";" & Adresse2 & ";" & Adresse3
        .Subject = "Bobbi Brown| " & Project_number & " " & Project_name & "| Forecast due " & Project_due
        .Body = "Dear All, " & Chr(10) & "I kindly remind you that forecasts for program " & Project_number & " " & Project_name & " are due " & Project_due & "." & Chr(10) & "Please enter your forecast " & "<a href=lien>here.</a>" & Chr(10) & "Best Regards," & Chr(10) & "Christian Chen"
        .Send
End with
End If
Next i
Application.ScreenUpdating = True
MsgBox "Your e-mails have been sent successfully", , "FIY"
End Sub

1 个答案:

答案 0 :(得分:2)

在将i变量用于Adresse变量之前,您没有设置Sub email_missing_forecast() Application.ScreenUpdating = False 'Déclaration des variables derniereligne = Range("B").End(xlUp).Row Project_number = Cells(1, 2).Value Project_name = Cells(2, 2).Value Project_due = Cells(3, 2).Value Lien = Cells(4, 2).Value Dim Objoutlook As New Outlook.Application Dim Objectmail 'Condition For i = 6 To derniereligne Adresse = Cells(i, "D").Value Adresse2 = Cells(i, "E").Value Adresse3 = Cells(i, "F").Value If Cells(i, "B").Value = "No" Then Set Objoutlook = New Outlook.Application Set Objectmail = Outlook.createitem(olmailitem) With Objectmail .To = Adresse & ";" & Adresse2 & ";" & Adresse3 .Subject = "Bobbi Brown| " & Project_number & " " & Project_name & "| Forecast due " & Project_due .Body = "Dear All, " & Chr(10) & "I kindly remind you that forecasts for program " & Project_number & " " & Project_name & " are due " & Project_due & "." & Chr(10) & "Please enter your forecast " & "<a href=lien>here.</a>" & Chr(10) & "Best Regards," & Chr(10) & "Christian Chen" .Send End with End If Next i Application.ScreenUpdating = True MsgBox "Your e-mails have been sent successfully", , "FIY" End Sub ,在循环中移动这些变量的声明可以解决您的问题:

private void cartItemsList_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "incrementButton") {
        try {
            int ID = e.CommandArgument;
            Label mainQuantity = (Label)e.Item.FindControl("quantity");
            mainQuantity.Text = mainQuantity.Text + 1;
            ((Label)e.Item.FindControl("quantity")).Text = mainQuantity.Text;
        } catch (Exception ex) {
            Response.Write(ex);
        }
    }
}