【发布时间】:2013-02-26 18:41:24
【问题描述】:
在 excel 中我有三列:
A: B: C:
UserName UsermailAddress RecordToBeDeleted
我在 excel 中使用下面的代码从 Outlook(使用 OFT 文件)向 Excel 电子表格 B 列中的每个电子邮件地址发送和发送电子邮件。
我的代码可以发送到 B 列中的每个电子邮件地址
我遇到的问题是,在电子邮件(OFT 文件)中,我有两个关键字(UserName 和 RecordToBeDeleted),我需要在与该邮件地址相关的每封电子邮件中替换它们。
代码在 OFT 文件中找到两个关键词,但只是将它们删除或替换为空条目。
我做错了什么,所以我可以替换OFT邮件消息中excel文件中的单词。
我在 excel 表中的 VBA 是:
Sub RunEmails()
Dim i As Integer
Dim rngCell As Range
For Each rngCell In Range("A2", "A" & CStr(Cells(Rows.Count, "A").End(xlUp).Row))
Call DoTest(rngCell.Offset(0, 1).Value, "JDoe@abc.com", rngCell.Offset(0, 2).Value, rngCell.Value)
Next rngCell
End Sub
Sub DoTest(EmailAddress As String, CCAddress As String, RecordToBeDeleted As String, UserName As String)
Dim oApp As New Outlook.Application
Dim olNewMail As Outlook.MailItem
Const Template As String = "D:\Documents\list\list-mail.oft"
Set olNewMail = oApp.CreateItemFromTemplate(Template)
olNewMail.Recipients.Add EmailAddress
olNewMail.HTMLBody = Replace(olNewMail.HTMLBody, ">UserName<", UserName)
olNewMail.HTMLBody = Replace(olNewMail.HTMLBody, ">RecordToBeDeleted<", RecordToBeDeleted)
olNewMail.VotingOptions = "Can distribution list be Deleted YES;Can distribution list be Deleted NO"
olNewMail.Send
End Sub
【问题讨论】:
-
我使用了以下 - 它有效! stackoverflow.com/questions/9147345/…
标签: excel vba outlook outlook-2010