从Excel电子表格填充数据的电子邮件

问题描述 投票:0回答:1

我接触的Excel电子表格。我想设置将电子邮件发送到特定的人,我选择和返回的电子邮件的正文中的联系信息下拉列表中。

我不知道如何让电子邮件自动填充而现在,在弹出的电子邮件在体内的联系信息“真”,而不是在单元格中返回文本值。

Sub DropDown7_Change()

    Dim answer As String

    answer = MsgBox("Are you sure you want to assign this lead?", _
        vbYesNo, "Send Email")
    '    Above code informs the user that an automated email will be sent

    'Code uses the users answer to either carryout the generated email process or to not save the changes.
    If answer = vbNo Then Cancel = True
    If Cancel = True Then Exit Sub

    If answer = vbYes Then  
        'Connects to outlook and retrieves information needed to create and send the email.
        Set OutlookApp = CreateObject("Outlook.Application")
        Set OlObjects = OutlookApp.GetNamespace("MAPI")
        Set newmsg = OutlookApp.CreateItem(olMailItem)

        'Contains the email address of the person receiving the email.
        newmsg.Subject = "Lead Assigned to You" 'Sets the automated subject line to the email
        newmsg.Body = "Hello," & vbNewLine & _
            "You have been assigned a lead. Please follow up with the contact" & vbNewLine & _
            ActiveCell.Offset(0, 3).Range("K5").Select
            ActiveCell.Offset(0, 6).Range("K5").Select
            ActiveCell.Offset(0, 7).Range("K5").Select

        'Above code has the body of the automated email
        newmsg.Display
    End If

End Sub ' End of function
excel vba email
1个回答
0
投票

如果你试图让那些OffsetRange("K5")值,那么你需要使用Offset.Value,这样Range("K5").Offset(0, 3).Value,这将获得价值3列单元格“K5”的权利。

下面的代码,将3个细胞列偏移细胞“K5”给你邮件正文添加值:

Sub DropDown7_Change()

    Dim answer As String

    answer = MsgBox("Are you sure you want to assign this lead?", _
        vbYesNo, "Send Email")
    '    Above code informs the user that an automated email will be sent

    'Code uses the users answer to either carryout the generated email process or to not save the changes.
    If answer = vbNo Then
        Exit Sub
    Else
        If answer = vbYes Then

            'Connects to outlook and retrieves information needed to create and send the email.
            Set OutlookApp = CreateObject("Outlook.Application")
            Set OlObjects = OutlookApp.GetNamespace("MAPI")
            Set newmsg = OutlookApp.CreateItem(olMailItem)

            'Contains the email address of the person receiving the email.
            newmsg.Subject = "Lead Assigned to You" 'Sets the automated subject line to the email
            newmsg.body = "Hello," & vbNewLine & _
                "You have been assigned a lead. Please follow up with the contact" & vbNewLine & _
                Range("K5").Offset(0, 3).Value & vbNewLine & _
                Range("K5").Offset(0, 6).Value & vbNewLine & _
                Range("K5").Offset(0, 7).Value & vbNewLine                    

            'Above code has the body of the automated email
            newmsg.Display
        End If
    End If

End Sub 
© www.soinside.com 2019 - 2024. All rights reserved.