在Excel中发送电子邮件时更改的精确单元格地址

时间:2019-08-01 11:39:34

标签: excel vba

我有一个共享的excel文件,我想在每次更改后发送电子邮件通知。我希望仅在单击“保存”按钮后才发送此电子邮件。 另外,在邮件正文中,我想清楚地了解已更改的单元格。是否有任何方法可以在“单元格”之后添加此信息?

这是我的代码

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim xOutApp As Object
Dim xMailItem As Object
Dim xName As String
Dim xrng As Range
On Error Resume Next

Set xrng = Range("A1:F300")
If Not Application.Intersect(xrng, Range(Target.Address)) _
       Is Nothing Then

Set xOutApp = CreateObject("Outlook.Application")
Set xMailItem = xOutApp.CreateItem(0)
xName = ActiveWorkbook.FullName
With xMailItem
    .To = "gfousteris@pharmathen.com"
    .CC = ""
    .Subject = "The workbook has been saved"
    .Body = "Cell(s) " & _
        " in the worksheet '" & Me.Name & "' were modified on " & _
        Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
        " by " & Environ$("username") & "." & Chr(13) & Chr(13) &       ActiveWorkbook.FullName
    .Display
   '.send
End With

Set xMailItem = Nothing
Set xOutApp = Nothing
End If
End Sub

0 个答案:

没有答案