Outlook MailItem HTMLBody Replace() 不工作 - 全新的

Outlook MailItem HTMLBody Replace() not working - brand new be gentle

好的,这是更新后的版本...不过仍然无法正常工作

        NextHTMLBody = nextMessage.HTMLBody
        NextHTMLBody = Replace(NextHTMLBody, "%Customer_Name%", bBodyName)
        NextHTMLBody = Replace(NextHTMLBody, "%##%", formPage.Controls("LoanNumber1").Value)

        With nextMessage
            .HTMLBody = NextHTMLBody
            .Subject = subjEmail
            .To = sendTo
            .Send
        End With

-------------这里有效.. 不确定我做了什么不同

        'Set body
        NextHTMLBody = nextMessage.HTMLBody
        NextHTMLBody = Replace(NextHTMLBody, "%Customer_Name%", bBodyName)
        NextHTMLBody = Replace(NextHTMLBody, "%##%", formPage.Controls("LoanNumber1").Value)

        With nextMessage
            .HTMLBody = NextHTMLBody
            '.Body = NextHTMLBody
            .Subject = subjEmail
            .To = sendTo
            '.Send
            .Display
        End With

替换在这里应该可以正常工作:

If InStr(nextMessage.HTMLBody, "%Customer_Name%") <> 0 Then
    NextHTMLBody = Replace(nextMessage.Body, "%Customer_Name%", bBodyName)
End If

但是在下一个块中,您将通过返回 nextMessage.HTMLBody 而不是继续 NextHTMLBody 来放弃上面执行的替换。您还从 Body 切换到 HTMLBody:不确定是否有共鸣。

If InStr(nextMessage.HTMLBody, "%##%") <> 0 Then

    NextHTMLBody = Replace(nextMessage.HTMLBody, "%##%", _
                             formPage.Controls("LoanNumber1").Value)
End If

最好的选择是更像这样的东西(你真的不需要这里的 If-Then):

NextHTMLBody = nextMessage.HTMLBody

NextHTMLBody = Replace(NextHTMLBody, "%Customer_Name%", bBodyName)

NextHTMLBody = Replace(NextHTMLBody, "%##%", _
                             formPage.Controls("LoanNumber1").Value)