首页 > 解决方案 > 有没有办法在电子邮件正文中提取 VBA 中的第一列值?

问题描述

我正在努力寻找一种方法来提取与找到的同一行匹配的第一列值cell.value并将其插入到电子邮件正文中。
换句话说:如果我的工作表上有“发送”一词,它应该从第一列(“A”)的同一行中获取匹配的名称并将其放在我的文本正文中。
这可能吗?

我的代码如下

Sub email()
    Dim r As Range
    Dim cell As Range 
    
    Set r = Range("F2:F100")
    
    For Each cell In r
        If cell.Value = "Send" Then
            Dim Email_Subject, Email_Send_From, Email_Send_To, _
            Email_Cc, Email_Body As String
    
            Dim Mail_Object, Mail_Single As Variant
            Dim Machine_Code As Long
            Dim Machine_Type As Long
    
            Email_Subject = "Reminder to perform activity"
            Email_Send_From = "George@JKhoney.com"
            Email_Send_To = "xsoxperience@JKhoney.com"
            Email_Cc = ""
            Email_Body = "Dear, This is a friendly reminder. There are pending actions regarding your activities please take actions accordingly" & ". Due date on " & cell.Value & "               This is an automatic e-mail with no response needed"
    
            On Error GoTo debugs
    
            Set Mail_Object = CreateObject("Outlook.Application")
            Set Mail_Single = Mail_Object.CreateItem(0)
    
            With Mail_Single
                .Subject = Email_Subject
                .To = Email_Send_To
                .CC = Email_Cc
                .Body = Email_Body
                .Send
            End With
        End If
    Next

debugs:
    If Err.Description <> "" Then MsgBox Err.Description
    Call email_2
End Sub

标签: excelvbaoutlook

解决方案


推荐阅读