java excel 模板 替换_通过vba excel发送时替换oft模板中的内容

我正在尝试使用outlook模板自动发送邮件,对链接到excel文件的文本进行微小更改 . 但是当我选择HTML格式时,结果不会出现 . 这是我的代码:我认为问题在于.HTMLbody行,因为代码中的其他所有内容都可以正常工作 . 有人可以帮忙吗?

Sub Test1()

'Working in Office 2000-2016

Dim OutApp As Outlook.Application

Dim OutMail As Outlook.MailItem

Dim cell As Range

Application.ScreenUpdating = False

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItemFromTemplate("C:\Users\600008809\Desktop\Reminder emails\Initial Survey.oft")

On Error GoTo cleanup

For Each cell In Columns("G").Cells.SpecialCells(xlCellTypeConstants)

If cell.Value Like "?*@?*.?*" And _

LCase(Cells(cell.Row, "H").Value) = "yes" _

And LCase(Cells(cell.Row, "I").Value) <> "send" Then

'Set OutMail = OutApp.CreateItem(0)

On Error Resume Next

With OutMail

.To = cell.Value

.Subject = "abc!"

.BodyFormat = olFormatHTML

.HTMLBody = Replace(.HTMLBody, "<< HiringManager >>", Worksheets("Tool").Range(4, 2))

'You can add files also like this

'.Attachments.Add ("C:\test.txt")

Set .SendUsingAccount = OutApp.Session.Accounts.Item("abc@xyz.com")

.Send

'.Display 'Or use Display

End With

On Error GoTo 0

Cells(cell.Row, "I").Value = "send"

Set OutMail = Nothing

End If

Next cell

cleanup:

Set OutApp = Nothing

Application.ScreenUpdating = True

End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值