我正在尝试在Excel中编码VBA宏,该宏将检查一列以验证是否存在“否”。如果是这样,将为.Send
创建一个预格式化的HTML正文电子邮件。这对我来说比较容易,但是要解决的困难是在HTML正文中引用单元格信息,以及首先通过在工作表1的“否”行中搜索文本字符串(名称)来引用多个表。在工作表2上输入文本,然后在相应行上拉出电子邮件单元格。然后,我想在电子邮件发送后将“否”单元格更改为“是”。我的普通电子邮件代码与实现此功能完全一样!这是我通常使用和理解的:
Sub Email_Send()
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Dim sendTo As String
sendTo = ""
Dim sendCC As String
sendCC = ""
Dim sendBCC As String
sendBCC = ""
Dim emailCell As Range
With ActiveSheet
For Each emailCell In .Range("F3", .Range("F3").End(xlDown))
If .Cells(emailCell.Row, "D").Text = "No" Then
sendTo = sendTo & "; " & emailCell.Text
End If
Next emailCell
End With
On Error Resume Next
With OutMail
.To = sendTo
.CC = sendCC
.BCC = sendBCC
.Subject = "URGENT: COMPANY FIRST DAY UPDATE"
.BodyFormat = olFormatHTML
`If the recipient is on row 546
.HTMLbody = "<p>Good Afternoon (Row 546 Name)</p><p>Your start date shall be (Row 546 Start Date). Your manager will be (Row 546 Manager Name). You will work the (Row 546 Shift Time) shift.</p><p>Thank you for your time</p>"
.Display
End With
On Error GoTo 0
End Sub
我知道If
命令将需要调整才能调用不同的工作表,但是我对如何实现这一点感到非常困惑。这是可行的吗,或者如果将HTML / VBA脚本缠绕在一起,是否会导致语法错误?另外,如果有人可以帮助您解决这个问题,我将不胜感激。我已经使用VBA几次,并且可以使用帮助来解释学习过程背后的逻辑!