2016-09-16 74 views
0

我在后台运行Outlook。使用Excel 2010中将更改的行号添加到邮件正文

我想要做如下:

  • 发送自动邮件定义者
  • 邮件的主体应该包含其中的变化发生
  • 的行数和列数它应细胞的一个指定列只工作

我有以下几点:

Private Sub Worksheet_Change(ByVal Target As Range) 
Dim APP_OUTLOOK As Object 
Dim MESSAGE As Object 

Set APP_OUTLOOK = CreateObject("Outlook.Application") 
Set MESSAGE = APP_OUTLOOK.CreateItem(0) 

If Not Intersect(Target, Range("A1:A1048576")) Is Nothing Then 
    With MESSAGE 
     .To = "[email protected]" 
     .Subject = "" 
     .Body = "hey buddy, something has changed please have a look at cell: " 
'the text should show: "hey buddy, something has changed please have a look at cell: A25000." 
     .Display 
    End With 
End If 
End Sub 
  • 如果单元格中的值从“”改变的东西或改变一个值,另一个值
  • 它是动态的,它应该只发送邮件,因为我不能指定一个确切的细胞
  • 单元格包含格式为“DD.MM.YY”日期

随着扎克的帮助下,我能解决我的问题。

下面是工作代码:

Private Sub Worksheet_Change(ByVal Target As Range) 
Dim APP_OUTLOOK As Object 
Dim MESSAGE As Object 

Set APP_OUTLOOK = CreateObject("Outlook.Application") 
Set MESSAGE = APP_OUTLOOK.CreateItem(0) 

    If Not Intersect(Target, Range("A1:A1048576")) Is Nothing Then 
     With MESSAGE 
      .To = "[email protected]" 
      .Subject = "" 
      .Body = "hey buddy," & vbNewLine & vbNewLine & "the file has been modified" & vbNewLine & vbNewLine & "following cell has a new entry: " & Target.Address & vbNewLine & vbNewLine & "the new entry has the value " & Target.Text & vbNewLine & vbNewLine & "please check the excel file" & vbNewLine & vbNewLine & "best wishes," & vbNewLine & "me" 
      .Display 
     End With 
    End If 
End Sub 
  • 我已经加入Target.Text显示该值和Target.Address是显示小区的行和列。

回答

0

我没有测试过你的代码,但它看起来应该可以工作。要更改单元格的地址,请在.Body声明末尾添加Target.Address