所以我们正在举办这个大型活动,我有一个Excel表格,其中包括每个人的姓名、电子邮件地址以及他们的行程文件(共有两个)
在代码中,
我一直在得到一个运行时错误440(自动化错误)在我试图添加附件的那些行... 不确定发生了什么或如何解决它,任何帮助都将不胜感激 代码
Cells(x, 3)
和Cells(x, 4)
。我想做的是在该列中向每个人发送“个性化”的电子邮件,其中包含他们的所有信息。在代码中,
for
循环只到3,因为我只是通过向自己发送电子邮件来测试它,不想最终收到1000封电子邮件: P我一直在得到一个运行时错误440(自动化错误)在我试图添加附件的那些行... 不确定发生了什么或如何解决它,任何帮助都将不胜感激 代码
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.
Dim olApp As Object
Dim objMail As Object
Dim body, head, filePath, subject As String
Dim x As Long
Set olApp = CreateObject("Outlook.Application")
'Create e-mail item
Set objMail = olApp.CreateItem(0)
filePath = "\\fileserver\homeshares\Tsee\My Documents\Metropolitan Sales\MNF"
subject = "Important Travel Information for MNF Event this weekend"
x = 1
For x = 1 To 3
head = "<HTML><BODY><P>Hi " & Cells(x, 1).Value & ",</P>"
body = body & "<BR /><P>We are looking forward to having you at our <STRONG>Metropolitan Night Football Event</STRONG> this upcoming Sunday, <STRONG>11/17</STRONG>! Note, that the Giants game time has changed from 8:30 PM to 4:25 PM.</P>"
body = body & "<BR /><P>Please find attached your travel information packet that contains important addresses and confirmation numbers. Please read through it and let me know if you have any questions.</P>"
body = body & "<BR /><P>If you need to reach me this weekend, please call my cell phone <STRONG>(631) 793-9047</STRONG> or email me.</P>"
body = body & "<BR /><P>Thanks,<BR />Liz</P></BODY></HTML>"
With objMail
.subject = subject
.To = Cells(x, 2).Value
.Attachments.Add = filePath & "/" & Cells(x, 3).Value
.Attachments.Add = filePath & "/" & Cells(x, 4).Value
.BodyFormat = olFormatHTML
.HTMLBody = head & body
.Send
End With
Next x
End Sub
Const olFormatHTML = 2
或者将.BodyFormat = olFormatHTML
替换为.BodyFormat = 2
。 - Siddharth RoutF8
逐步执行代码吗? - Siddharth Rout