vba 不使用 vlookup

vba not working with vlookup

我正在尝试编写一个文档,该文档会根据特定条件自动向特定人员发送电子邮件。我的代码可以正常工作,并且对我所拥有的感到满意。

但是....

当我将工作表上的电子邮件地址更改为 vlookup 时,我的编码不再提取电子邮件地址。

有什么办法可以解决这个问题吗?提前致谢。代码如下。

Sub Button1_Click()

Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim StrBody As String

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")

On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants) 
    If cell.Value Like "?*@?*.?*" And _
       LCase(Cells(cell.Row, "C").Value) = "true" Then 

        Set OutMail = OutApp.CreateItem(0)
        On Error Resume Next
        With OutMail
            .To = cell.Value
            .Subject = "Urgent Training Notification  - Action Required"
            .Body = "Dear " & Cells(cell.Row, "A").Value _
                  & vbNewLine & vbNewLine & _
                    "Please be aware, " & Cells(cell.Row, "D") & " is required to update the following training:" & vbNewLine & _
                    " " & vbNewLine & _
                    Cells(cell.Row, "E") & vbNewLine & _
                    " " & vbNewLine & _
                    "This must be rectified within 14 Days." & vbNewLine & _
                    " " & vbNewLine & _
                    " " & vbNewLine & _
                    "Any issues, please escalate as required." & vbNewLine & _
                    "Many thanks."

            .Send  'Or use Display
        End With
        On Error GoTo 0
        Set OutMail = Nothing
    End If
Next cell

cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub

同意@Rawrplus,尝试理解代码真的很有意义。无论如何,如果您对自己的代码满意,请替换:

SpecialCells(xlCellTypeConstants)

与:

SpecialCells(xlCellTypeFormulas)

正如我之前所说,我不会使用 SpecialCells,但同样,您对代码很满意。

还有一件事;您在 C 列中是否有一个公式表示真或假?然后也删除 "true" 并在代码中键入 True。

祝你好运