复制其他单元格以使用Excel添加到电子邮件

时间:2013-08-09 14:09:50

标签: excel vba outlook

我有这个代码根据单元格a的变化发送和发送电子邮件,但是我想让电子邮件正文中的其他单元格的内容更具体地为最终用户找到问题。我无法找到针对我想要的特定细胞的最佳方法。任何帮助,将不胜感激!

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect([A2:A1000], Target) Is Nothing Then
    Set olApp = CreateObject("Outlook.application")
    Set M = olApp.CreateItem(olMailItem)
   Dim rngTo As Range
    Dim rngBody As Range
    Dim objOutlook As Object
    Dim objMail As Object
    Dim Issues As String
    Dim Desc As String
    Issues = Target.row


    With ActiveSheet
        'here is where i'm trying to get the contents of "F"
        Desc = Range("F" & Issues)
        Set rngBody = Intersect([A2:A1000], Target)
    End With
    rngBody.Copy

    With M
        .Subject = "Issue Tracker Has Changed"
        .Body = "The Status of Your Issue" & Desc & " Has Changed to " & rngBody
        .Recipients.Add "jane.doe@whatever.org"
        .Send
    End With
End If
End Sub

enter image description here

1 个答案:

答案 0 :(得分:0)

我通过获取Target的行值并将其与我需要数据的列合并并在体内将其作为字符串返回来解决这个问题。

    Dim Issues As String
    Dim Desc As String
    Issues = Target.row

    Desc = Range("F" & Issues)


.Body = "The Status of Your Issue" & Desc & " Has Changed to " & rngBody.Value

通过添加这些行我能够完成我的问题