我从 VBA 开始。这一次,我正在为商务电子邮件创建一个简单的自动化程序,可以从 Excel 发送,同时使用 OFT 模板。下面的代码非常适合替换文本,但不能用于创建适当的条件。我需要添加一个条件,如果单元格为空,则不执行任何操作,如果包含某些内容,则在单元格中添加“on”和文本。代码的“更改源”部分显然是错误的。有人可以帮忙吗?
Sub Test()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim x As Variant
Dim Sour As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
x = Cells(1, 3)
vTemplateBody = otlNewMail.HTMLBody
strFind = "NAME1"
strNew = Cells(x, 3)
.HTMLBody = Replace(.HTMLBody, strFind, strNew)
'Change SOURCE
vTemplateBody = otlNewMail.HTMLBody
strFind = "SOURCE1"
strNew = if Cells(x, 3) = "n/a" Then .Skip Else = " on " & Cells(x, 12)
.HTMLBody = Replace(.HTMLBody, strFind, strNew)