在Excel文件OFT我有三列:Excel的VBA在Outlook中替換文本從Excel
A: B: C:
UserName UsermailAddress RecordToBeDeleted
我用下面的代碼在Excel中發送和從Outlook電子郵件(使用OFT文件)到各Excel電子表格B列中的電子郵件地址。
我的作品就在B列發送到每個郵件地址的代碼
我的問題是,在電子郵件的信息(OFT文件)我有兩個關鍵字(UserName
和RecordToBeDeleted
)我需要在與該郵件地址一起發送的每封電子郵件中進行替換。
代碼找到OFT文件中的兩個關鍵詞,但只刪除它們或用空條目替換它們。
我在做什麼錯誤,以便我可以從OFT郵件中的excel文件中替換單詞。
的VBA我在Excel表:
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, "[email protected]", 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
我用了以下 - 它的工作! https://stackoverflow.com/questions/9147345/error-in-sending-mail-through-outlook-using-vb#new-answer?newreg=b23a1b588c6a4ba09b18ec756a34347b – 2015-08-05 06:16:14