【发布时间】:2016-07-27 10:59:28
【问题描述】:
使用 Ron de Bruin 的大部分部分在包含邮件地址的列中运行一个宏。
宏运行得很好,但只发送column B 中的第一个命中并且当我尝试观看它时不显示任何其他命中?可能是什么问题?
代码是为了让我可以从 Outlook 中获取默认签名,这就是为什么它在代码中首先是 .Display。
Sub mail_HTML()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
strbody = "<H3>Hei " & Cells(cell.Row, "E").Value & "</H3>" _
& "<p>" & Range("k4") & "<p>"
On Error Resume Next
With OutMail
.Display
.To = cell.Value
.Subject = Range("K12").Value
.HTMLBody = strbody & .HTMLBody
'You can add files also like this
'.Attachments.Add Range("O1").Value
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
它失败了,因为您在循环中将
OutMail设置为Nothing,但永远不会在循环中再次实例化它。由于您的On Error Resume Next行,代码不会失败。尝试在循环中设置OutMail。 -
@Ambie 就是这样!谢谢
-
您能否也给我一个提示,说明为什么附件无法加载(是的,我知道我已经删除了它;))
-
你应该为此提出一个新问题。
-
想通了。只是我懒