我有一个带有HTML正文的模板。我想根据单元格F的值包含一行。
如果在单元格F中,则写入"不完整"然后它应包括短语"您的付款不完整"进入电子邮件文本。
如果在单元格F中,则写入"完成"一个空间被添加到HMTL主体。
我怎样才能做到这一点?
With OutMail
.To = Cells(cell.Row, "C").Value
.Subject = "Request" & Cells(cell.Row, "E").Value
.BodyFormat = olFormatHTML
.HTMLBody = Cells(cell.Row, "A").Value & Cells(cell.Row, "B").Value _
& "<p>The status of your invoice is</p>" _
If (Cells(cell.Row, "F").Value) = "incomplete" then:
.HTMLBody = "<p> Your payment is incomplete<p/>" _
Else
.HTMLBody = "<p> <p/>" _
& "<p>Thank you</p>" _
答案 0 :(得分:0)
如果循环看起来像这样的话。
If condition
'if true
Else
'if false
EndIf
答案 1 :(得分:0)
你的代码中有一些错误,有些东西会造成混乱。首先是if语句。写下这些,改为:
If (Cells(cell.Row, "F").Value) = "incomplete" Then
.HTMLBody = "<p> Your payment is incomplete<p/>"
Else
.HTMLBody = "<p> <p/>" & _
"<p>Thank you</p>"
End If
其次,您的单元格引用不正确。列在单元格方法中由数字引用(即F = 6)。期望活动纸张是预期纸张也是有风险的。创建对它的引用以确保
Dim TargetSheet as WorkSheet
Set TargetSheet = Worksheets("MySheet")
TargetSheet.Cells(cell.Row, 6).Value
答案 2 :(得分:0)
使用IIF()功能
With OutMail
.To = Cells(cell.Row, "C").value
.Subject = "Request" & Cells(cell.Row, "E").value
.BodyFormat = olFormatHTML
.HTMLBody = Cells(cell.Row, "A").value & Cells(cell.Row, "B").value _
& "<p>The status of your invoice is</p>" _
& IIf(Cells(cell.Row, "F").value = "incomplete", "<p> Your payment is incomplete<p/>", "<p> <p/><p>Thank you</p>")
End With
只需根据需要调整函数的两个结果:就像现在一样,它添加了"<p> Your payment is incomplete<p/>"
或"<p> <p/><p>Thank you</p>"
,与Cells(cell.Row, "F").value
相关匹配&#34;不完整&#34; 或不