0

您好,我有一个宏,应该将电子邮件发送到我的 C 列上的地址,并复制到 F 列中的电子邮件地址和一些文本...但我的问题是它没有遍历每个名​​称,只是转到最后一个...有人可以帮我弄清楚我做错了什么吗?

Sub Send_Email()

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim cel As Range

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

For Each cel In Range(("C2"), Range("C2").End(xlDown))

    strbody = "Hi there" & vbNewLine & vbNewLine & _
            "My name Is William" & vbNewLine & _
            "I work at Fair" & vbNewLine & _
            "Bye" & vbNewLine & _
            "WH"

    On Error Resume Next
    With OutMail
        .To = cel.Value    '"email.address@fair.com"
        .CC = cel.Offset(0, 3).Value & "Ivan.Martinez@fair.com"
        .BCC = ""
        .Subject = "Information You Requested"
        .Body = strbody
        .Display
        '.Attachments.Add ("C:\test.txt")
        '.Send
    End With
    On Error GoTo 0
Next cel

Set OutMail = Nothing
Set OutApp = Nothing

结束子

4

2 回答 2

0

尝试将此添加到您的代码中:

Dim lastRow As Long  
Dim Rng As Range  

lastRow = Range("C:C").Find("*", Range("C1"), Searchdirection:=xlPrevious).Row
Set Rng = Range(Cells(2,"C"),Cells(lastRow,"C"))

For Each Cel in Rng

'The rest of your code goes here.

这是设置范围的一种更可靠的方法。

于 2013-11-01T22:04:12.073 回答
0
For Each cel In Range(("C2"), Range("C2").End(xlDown)).Cells
于 2013-11-03T17:17:03.093 回答