提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何在Excel中修改某个单元格的情况下发送电子邮件?

本文正在讨论如果在Excel中修改了某个范围内的任何单元格,则通过Outlook发送电子邮件。

如果使用VBA代码修改了特定范围内的单元格,则发送电子邮件

Office选项卡在Office中启用选项卡式编辑和浏览,使您的工作更轻松......
Kutools for Excel - 最佳办公生产力工具将解决您的大部分Excel问题
  • 重用任何东西: 将最常用或最复杂的公式,图表和其他任何内容添加到您的收藏夹中,并在将来快速重复使用它们。
  • 超过20文本功能: 从文本字符串中提取数字; 提取或删除部分文本; 将数字和货币转换为英语单词...
  • 合并工具:多个工作簿和表格合二为一; 合并多个单元格/行/列而不丢失数据; 合并重复行和总和...
  • 拆分工具:根据价值将数据拆分为多个表格; 一个工作簿到多个Excel,PDF或CSV文件; 一列到多列......
  • 粘贴跳过 隐藏/过滤行; 数和总和 按背景颜色; 创建邮件列表和 通过Cell的价值发送电子邮件...
  • 超级过滤器: 创建高级过滤方案并应用于任何工作表; 排序 按周,日,频率等; 筛选 通过大胆,公式,评论......
  • 超过300强大的功能; 适用于Office 2007-2019和365; 支持所有语言; 在公司轻松部署; 全功能60天免费试用。

如果使用VBA代码修改了特定范围内的单元格,则发送电子邮件


如果您需要在范围为A2:E11的单元格在特定工作表中修改时附带有活动工作簿的情况下自动创建新电子邮件,以下VBA代码可以为您提供帮助。

1。 在您需要发送电子邮件的工作表中,根据其修改过的单元格在特定范围内发送电子邮件,右键单击工作表选项卡,然后单击 查看代码 从上下文菜单。 看截图:

2。 在弹出 Microsoft Visual Basic for Applications 窗口,请复制并粘贴下面的VBA代码到代码窗口。

VBA代码:如果在Excel中修改了指定范围内的单元格,则发送电子邮件

Private Sub Worksheet_Change(ByVal Target As Range)
'Updated by Extendoffice 2017/9/12
    Dim xRgSel As Range
    Dim xOutApp As Object
    Dim xMailItem As Object
    Dim xMailBody As String
    On Error Resume Next
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set xRg = Range("A2:E11")
    Set xRgSel = Intersect(Target, xRg)
    ActiveWorkbook.Save
    If Not xRgSel Is Nothing Then
        Set xOutApp = CreateObject("Outlook.Application")
        Set xMailItem = xOutApp.CreateItem(0)
        xMailBody = "Cell(s) " & xRgSel.Address(False, False) & _
            " in the worksheet '" & Me.Name & "' were modified on " & _
            Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
            " by " & Environ$("username") & "."

        With xMailItem
            .To = "Email Address"
            .Subject = "Worksheet modified in " & ThisWorkbook.FullName
            .Body = xMailBody
            .Attachments.Add (ThisWorkbook.FullName)
            .Display
        End With
        Set xRgSel = Nothing
        Set xOutApp = Nothing
        Set xMailItem = Nothing
    End If
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

笔记:

1)。 在代码中, A2:E11 是您将基于其发送电子邮件的范围。

2)。 请根据需要更改电子邮件正文 xMailBody 在代码中的行。

3)。 更换 电邮地址 与收件人的电子邮件地址一致 .To =“电子邮件地址”.

4)。 按行更改电子邮件主题 .Subject =“工作表修改”&ThisWorkbook.FullName.

3。 按 其他 + Q 键同时关闭 Microsoft Visual Basic for Applications 窗口。

从现在开始,范围为A2:E11的任何单元格都会被修改,将会创建一个新的电子邮件并附带更新后的工作簿。 所有指定的字段,如主题,收件人和电子邮件正文将列在电子邮件中。 请发送电子邮件。

注意:当您使用Outlook作为您的电子邮件程序时,VBA代码才起作用。


相关文章:


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    James · 25 days ago
    Hello. How do I modify the code so that an e-mail is sent to another e-mail address if another range of cells is edited?
    • To post as a guest, your comment is unpublished.
      joseph · 6 days ago
      Any help on this request? I am having same issue. I want to add multiple email address per row, but when I change one row, the entire worksheet changes. How can I limit the changes only to one row?
  • To post as a guest, your comment is unpublished.
    Ioana · 6 months ago
    hi; is there a way to change text displayed using information from other cells (from first row and first column)? for example, if I change cell K15, I want to include in the message info on cells A15 and K1? what should I change in the code? thank you very much
  • To post as a guest, your comment is unpublished.
    Jimmy Joseph · 6 months ago
    I have tried above VBA code: Send email if cell in a specified range is modified in Excel. This VBA works for me except sending email. When the data is modified in the given range an email is automatically generated with modified cell details. However, the email is not automatically sending to the recipient and the user has to click send button in the email. What I am looking here is, the email has to send to the recipients automatically when it is generated. Please help me to provide a code for this. Many thanks
    • To post as a guest, your comment is unpublished.
      crystal · 6 months ago
      Hi Jimmy Joseph,
      Please replace the line ".Display" with ".Send". Hope I can help. Thanks for commenting.
  • To post as a guest, your comment is unpublished.
    sagar · 8 months ago
    if i have to send that entire row then?
  • To post as a guest, your comment is unpublished.
    Brad · 9 months ago
    Great information.
    Question regarding the information that can be added to the email.
    Using your example above....

    If you had a value in F4, how would you include the F4 Value in the email that was generated when D4 was modified??
  • To post as a guest, your comment is unpublished.
    Sonu · 9 months ago
    If i want to send the cell value instead of the address..then what shall I change in the code?
    • To post as a guest, your comment is unpublished.
      crystal · 7 months ago
      Hi,
      You can try the below VBA code.

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRgSel As Range
      Dim xOutApp As Object
      Dim xMailItem As Object
      Dim xMailBody As String
      On Error Resume Next
      Application.ScreenUpdating = False
      Application.DisplayAlerts = False
      Set xRg = Range("A2:E11")
      Set xRgSel = Intersect(Target, xRg)
      ActiveWorkbook.Save
      If Not xRgSel Is Nothing Then
      Set xOutApp = CreateObject("Outlook.Application")
      Set xMailItem = xOutApp.CreateItem(0)
      xMailBody = "Cell(s) " & xRgSel.Address(False, False) & _
      xRgSel.Value & _
      " in the worksheet '" & Me.Name & "' were modified on " & _
      Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
      " by " & Environ$("username") & "."

      With xMailItem
      .To = "Email Address"
      .Subject = "Worksheet modified in " & ThisWorkbook.FullName
      .Body = xMailBody
      .Attachments.Add (ThisWorkbook.FullName)
      .Display
      End With
      Set xRgSel = Nothing
      Set xOutApp = Nothing
      Set xMailItem = Nothing
      End If
      Application.DisplayAlerts = True
      Application.ScreenUpdating = True
      End Sub
  • To post as a guest, your comment is unpublished.
    Mahadev · 10 months ago
    Dear Admin,


    I need your help,



    I have an excel to monitor daily work done details by our worker from the field, so is this possible to trigger a mail from excel sheet if that guy failed to update the data in that excel sheet on given time.
  • To post as a guest, your comment is unpublished.
    Sissy Jones · 10 months ago
    I was able to create the macro, however I'm having a problem. I would like to automatically send an email when a cell reaches a certain threshold. The cell is a formula. When the calculation sum goes below the said threshold it doesn't do anything; however, if I type directly into the cell it will process the macro as planned. Does the formula mess up the macro?
  • To post as a guest, your comment is unpublished.
    Pankaj Shukla · 1 years ago
    I am stuck in below VB code. I am trying to get email notification to the user where the data has been changed. Email is working but when I make any change email initiated at once but I want email when excel sheet is saved and closed after making all the changes to all users who impacted. Also this should be working for any of the sheets in entire excel workbook.

    Please help...

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    '****Declaration of objects and variables******

    Dim xRgSel As Range Dim xOutApp As Object Dim xMailItem As Object Dim xMailBody As String Dim mailTo As String

    On Error Resume Next

    Sheets("TargetSheet").Range("TargetRange").Select

    Application.ScreenUpdating = False Application.DisplayAlerts = False

    'Set xRg = Range("A" & Rows.Count).End(xlUp).Row

    Set xRg = Range("A2:DA1000")
    Set xRgSel = Intersect(Target, xRg)


    ActiveWorkbook.Save
    '**********Outlook Application Opening***********

    If Not xRgSel Is Nothing Then

    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailItem = xOutApp.CreateItem(0)

    xMailBody = "Cell(s) " & xRgSel.Address(False, False) & _
    " in the worksheet '" & Me.Name & "' were modified on " & _
    Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
    " by " & Environ$("username") & "."
    '***********Finding recipient List************

    If Cells(xRgSel.Row, "A").Value = "Pankaj" Then

    mailTo = "pank12***@gmail.com"

    End If

    If Cells(xRgSel.Row, "A").Value = "Nitin" Then

    mailTo = "pank****@gmail.com"

    End If

    If Cells(xRgSel.Row, "A").Value = "Chandan" Then

    mailTo = "pakxro**@gmail.com"

    End If
    '*************Email composing*************

    With xMailItem

    .To = mailTo
    .Subject = "Worksheet modified in " & ThisWorkbook.FullName
    .Body = xMailBody
    '.Attachments.Add (ThisWorkbook.FullName)
    .Display

    End With

    Set xRgSel = Nothing
    Set xOutApp = Nothing
    Set xMailItem = Nothing

    End If

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub