电子邮件macros没有下一个错误

你好我有这个代码在这里返回一个错误“为没有下一个”,它突出了底部的底部一路。

为什么发生这种情况? 我只是试图在我的电子邮件正文中插入某些单元格的值。

有人可以帮忙吗?

Sub Notify() Dim name, email, evnt, status As Range Dim SigString As String Dim Signature As String SigString = Environ("appdata") & _ "\Microsoft\Signatures\Will.txt" If Dir(SigString) <> "" Then Signature = GetBoiler(SigString) Else Signature = "" End If For Each name In Range(("B2"), Range("B2").End(xlDown)) For Each email In Range(("C2"), Range("C2").End(xlDown)) For Each evnt In Range(("E2"), Range("E2").End(xlDown)) For Each status In Range(("F2"), Range("F2").End(xlDown)) On Error Resume Next With CreateObject("Outlook.Application").CreateItem(0) .To = email.Value .CC = email.Offset(0, 1).Value .Subject = "Information You Requested" .Body = "Dear " & name.Value & "," & vbNewLine & vbNewLine & _ "As you may know the 2014 race started on November 4th and will be open until November 15th in order for you to select your candidate." & vbNewLine & vbNewLine & _ "Your 2014 election is now On Hold since you have a previous " & evnt.Value & "event with a " & status.Value & "status in Workday. " & vbNewLine & vbNewLine & _ "In order for you to be able to finalize your Elections you need to finalize the event above as soon as possible." & vbNewLine & vbNewLine & _ "If you have any questions about this task please call us at 1-877-777-7777 option 8" & vbNewLine & vbNewLine & _ "Regards" & vbNewLine & vbNewLine & _ "Department" .Display '.Attachments.Add "C:\test.txt" '.Send End With Next End Sub Function GetBoiler(ByVal sFile As String) As String 'Dick Kusleika Dim fso As Object Dim ts As Object Set fso = CreateObject("Scripting.FileSystemObject") Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2) GetBoiler = ts.readall ts.Close End Function 

你有4 For Each但只有一个Next

你需要有另外3个Next 。 看到这个

 Sub Notify() ' '~~> Rest of the code ' For Each Name In Range(("B2"), Range("B2").End(xlDown)) For Each Email In Range(("C2"), Range("C2").End(xlDown)) For Each evnt In Range(("E2"), Range("E2").End(xlDown)) For Each Status In Range(("F2"), Range("F2").End(xlDown)) ' '~~> Rest of the code ' Next Next Next Next End Sub