跳到主要内容

如何在复制和粘贴指定范围到Excel中的电子邮件正文中发送电子邮件?

在许多情况下,Excel工作表中指定范围的内容可能对您的电子邮件通信很有用。 在本文中,我们将介绍一种直接在Excel中发送将具有指定范围的电子邮件粘贴到电子邮件正文中的方法。

发送具有指定范围的电子邮件,粘贴到Excel中的电子邮件正文中
使用出色的工具发送指定范围的电子邮件,并将其粘贴到电子邮件正文中

有关在Excel中发送邮件的更多教程...


发送具有指定范围的电子邮件,粘贴到Excel中的电子邮件正文中

以下VBA代码可以帮助您直接在Excel中复制范围并将其粘贴到Outlook电子邮件正文中。 请执行以下操作。

1.在工作表中包含您需要复制的范围,按 其他 + F11 同时打开 Microsoft Visual Basic应用程序 窗口。

2.在开幕 Microsoft Visual Basic应用程序 窗口,请点击 工具 > 参考资料 如下图所示。

3.在 参考– VBAProject 对话框,请查找并检查 Microsoft Outlook对象库 选项,然后单击 OK 按钮。

4。 点击 插页 > 模块,然后将下面的VBA代码复制并粘贴到“模块”窗口中。

VBA代码:发送具有指定范围的电子邮件,粘贴到Excel中的电子邮件正文中

Sub Send_Email()
'Updated by Extendoffice 20200119
    Dim xRg As Range
    Dim I, J As Long
    Dim xAddress As String
    Dim xEmailBody As String
    Dim xMailOut As Outlook.MailItem
    Dim xOutApp As Outlook.Application    
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    For I = 1 To xRg.Rows.Count
        For J = 1 To xRg.Columns.Count
            xEmailBody = xEmailBody & "  " & xRg.Cells(I, J).value
        Next
        xEmailBody = xEmailBody & vbNewLine
    Next
    xEmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & xEmailBody & vbNewLine
    With xMailOut
        .Subject = "Test"
        .To = ""
        .Body = xEmailBody
        .Display
        '.Send
    End With
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

:

  • 1)。 请更改电子邮件正文 xEmailBody =“嗨”&vbLf&vbLf&“要添加的邮件正文”&vbLf&vbLf&xEmailBody&vbNewLine 如你所需。
  • 2)。 请指定您的电子邮件收件人和主题(.到= .Subject =“测试”) 代码中的行。

5。 按 F5 键来运行代码。 在弹出 Kutools for Excel 对话框,请选择您需要粘贴到电子邮件正文中的范围,然后单击 OK 按钮。 看截图:

6.现在,将创建一封包含指定收件人,主题,正文和所选Excel范围的电子邮件,请单击 提交 按钮发送此电子邮件。 请参阅显示的屏幕截图。

备注:仅当您将Outlook用作电子邮件程序时,VBA代码才起作用。


使用出色的工具发送指定范围的电子邮件,并将其粘贴到电子邮件正文中

如果您不使用Outlook,但仍想直接在Excel中直接发送电子邮件,并在其中粘贴指定的范围数据,则强烈建议您使用 发电子邮件 实用程序 Kutools for Excel 为了你。 使用此功能,您只需要配置电子邮件地址的传出服务器,然后以后再通过此电子邮件地址直接在Excel中发送电子邮件。

申请前 Kutools for Excel首先下载并安装.

1.首先,您需要准备一个带有必填字段的邮件列表。

  • Tips:邮件列表必须至少包含2行,并且第一行必须为标头(假设您要将电子邮件发送到Excel中的两个电子邮件地址,请输入这两个电子邮件地址,标头为“ Email”,如下所示) )。
  • 或者,您可以使用以下命令轻松创建邮件列表 创建邮件列表 功能。

2.选择范围,将数据添加到电子邮件正文,然后按 按Ctrl + C 键复制它。

3.选择整个邮件列表(包括标题),单击 Kutools 加 > 发电子邮件。 看截图:

4.然后 发电子邮件 弹出对话框。

  • 4.1)所选邮件列表的项目填充在相应的字段中(您可以根据需要在邮件列表中添加更多字段);
  • 4.2)点击电子邮件正文框,然后按 按Ctrl + V 键将选定的范围数据粘贴到其中。 之后,根据需要添加其他内容;
  • 4.3取消选中 通过Outlook发送电子邮件 框;
  • 2.4)点击 发送服务器设置 按钮。 看截图:

5.然后 传出服务器(SMTP)设置–新方案 对话框弹出。 请在电子邮件地址中填入其服务器设置,并在选中以下内容后指定一个文件夹来保存所有已发送的邮件 将发送的电子邮件保存到 框,然后单击 OK 按钮保存设置。

6.返回到 发电子邮件 对话框中,单击 提交 按钮发送电子邮件。

从现在开始,您可以直接在Excel中发送具有此功能的电子邮件。

  如果您想免费试用(30天)此实用程序, 请点击下载,然后按照上述步骤进行操作。


相关文章:

将电子邮件发送到Excel单元格中指定的电子邮件地址
假设您有一个电子邮件地址列表,并且您想直接在Excel中批量向这些电子邮件地址发送电子邮件。 如何实现呢? 本文将向您展示将电子邮件发送到Excel单元格中指定的多个电子邮件地址的方法。

在Excel中发送电子邮件时插入Outlook签名
假设您想直接在Excel中发送电子邮件,如何在电子邮件中添加默认的Outlook签名? 本文提供了两种方法来帮助您在Excel中发送电子邮件时添加Outlook签名。

发送带有Excel中附加的多个附件的电子邮件
本文讨论的是通过带有Excel中附加的多个附件的Outlook发送电子邮件。

如果在Excel中已达到到期日期,则发送电子邮件
例如,如果C列中的截止日期小于或等于7天(当前日期为2017/9/13),则向A列中的指定收件人发送电子邮件提醒,并在B列中指定内容。实现这一目标? 本文将提供一种VBA方法来详细处理它。

根据Excel中的单元格值自动发送电子邮件
假设您要基于Excel中指定的单元格值通过Outlook向特定收件人发送电子邮件。 例如,当工作表中单元格D7的值大于200时,将自动创建一封电子邮件。 本文介绍了一种VBA方法,可帮助您快速解决此问题。

有关在Excel中发送邮件的更多教程...

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (22)
Rated 4.5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
The only issue is that the format of the table is not maintained in the mail. Can you let me know how do we preserve the format of the table in the mail, I have the same issue, could you see if you could update it please, otherwise this is excellent.
Many thanks
Rated 4.5 out of 5
This comment was minimized by the moderator on the site
Hi Andy Mitchell,
If you want to maintain the format of the table, the following VBA script can do you a favor. Please give it a try. Thank you.
Sub Send_Email()
'Updated by Extendoffice 20220616
    Dim xRg As Range
    Dim I, J As Long
    Dim xAddress As String
    Dim xMailOut As Object
    Dim xOutApp As Object
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    With xMailOut
        .Subject = "Test"
        .To = ""
        .HTMLBody = RangetoHTML(xRg)
        .Display
        '.Send
    End With
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

 ' The following VBA script is cited from this page:
 ' https://stackoverflow.com/questions/18663127/paste-excel-range-in-outlook
Function RangetoHTML(rng As Range)
' By Ron de Bruin.
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With

    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With

    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.ReadAll
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function
This comment was minimized by the moderator on the site
This worked perfectly, thank you so much.
I can now add my spin on it to get it doing what I need.
This comment was minimized by the moderator on the site
Hi Paul Johnson,

Very happy to help you solve the problem. Have a good day at work.
This comment was minimized by the moderator on the site
hello,
can you help me on below
I have create excel sheet & updated 10 supplier mail detailI have send mail through excel to all 10 supplier with individual sheet attachment with individual mail.
I want to paste excel data in outlook body instead of attachment in mail
can any one help me
This comment was minimized by the moderator on the site
Hi,
Instead of selecting the range, I want to select multiple pivots in the excel.
can you please help me.
This comment was minimized by the moderator on the site
Hi,
Instead of selecting the range manually, I want to select the range automatically.
This comment was minimized by the moderator on the site
Hi Raman,
In the below code, please replace the range "A1:C5" in line Set xRg = Range("A1:C5") with your own range.

Sub Send_Email()
Dim xRg As Range
Dim I, J As Long
Dim xAddress As String
Dim xEmailBody As String
Dim xMailOut As Outlook.MailItem
Dim xOutApp As Outlook.Application
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Range("A1:C5")
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xMailOut = xOutApp.CreateItem(olMailItem)
For I = 1 To xRg.Rows.Count
For J = 1 To xRg.Columns.Count
xEmailBody = xEmailBody & " " & xRg.Cells(I, J).Value
Next
xEmailBody = xEmailBody & vbNewLine
Next
xEmailBody = "Hi" & vbLf & vbLf & " body of message you want to add" & vbLf & vbLf & xEmailBody & vbNewLine
With xMailOut
.Subject = "Test"
.To = ""
.Body = xEmailBody
.Display
'.Send
End With
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi experts, Do we have updates on how the format maintained?
This comment was minimized by the moderator on the site
Hi Ther,
Can't figure it out. Sorry for that.
This comment was minimized by the moderator on the site
i am seeing a compile error (User-defined type not defined". Please help me out to overcome this.
This comment was minimized by the moderator on the site
Hi,
Please get into the Reference window by clicking Tools > references. Scroll down to find and check the Microsoft Outlook Object Library box and click the OK button to finish the setting.
This comment was minimized by the moderator on the site
this is pasting as a text. Kindly suggest how to send the table or the same format which is copied from the excel.
This comment was minimized by the moderator on the site
Code to send automatically after selecting after ok
This comment was minimized by the moderator on the site
Hi
This code is vary excellent, by using the code i have completed my 90% of my project.
I have same issue as mentioned by Anirudh that is table formatting. How can i format the table in email.
Please help me......
This comment was minimized by the moderator on the site
Good Day,
The problem can't be solved yet. Sorry for the inconvenience and thank you for your comment.
This comment was minimized by the moderator on the site
Hi, Is there any update on below.......
This comment was minimized by the moderator on the site
Hi, Also I Wanted code for "Filter by Date".
I am working on project, on that project I wanted to filter the data by the date, actually we have filter/hide the and last 05 days to current date data and we have highlight all other data.
Please help me to complete this project.
Your help is very great-full for me.
This comment was minimized by the moderator on the site
This is great. It is working as expected. The only issue is that the format of the table is not maintained in the mail. Can you let me know how do we preserve the format of the table in the mail
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations