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

or

如何在Excel中通过vba发送邮件时将签名插入到Outlook电子邮件中?

在Excel中运行VBA代码发送电子邮件时,Outlook签名将不会自动显示在电子邮件正文中。 本文讨论如何使用Excel中的VBA代码发送电子邮件,并在电子邮件正文中显示Outlook签名。

通过Excel VBA发送时,将签名插入到Outlook电子邮件中


根据创建的邮件列表通过Outlook轻松发送电子邮件:

在此 发电子邮件 Kutools for Excel的实用工具可帮助用户通过基于Excel中创建的邮件列表通过Outlook发送电子邮件。 查看屏幕截图:

Kutools for Excel 包含了比300更方便的Excel工具。 免费试用60天无限制。 立即下载免费试用版

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

通过Excel VBA发送时,将签名插入到Outlook电子邮件中


假设您需要将电子邮件发送到电子邮件地址列表,请在所有发送电子邮件中包含Outlook签名。 请做如下。

1。 请将下面的VBA 2中的.Body行替换为VBA 1中的代码。 在VBA 2中,移动 。显示 排队直到它位于下方 使用xMailOut 线.

VBA 1:在Excel中使用签名发送电子邮件的模板

.HTMLBody = "This is a test email sending in Excel" & "<br>" & .HTMLBody

VBA 2:将电子邮件发送到Excel中单元格中指定的电子邮件地址

Sub SendEmailToAddressInCells()
    Dim xRg As Range
    Dim xRgEach As Range
    Dim xRgVal As String
    Dim xAddress As String
    Dim xOutApp As Outlook.Application
    Dim xMailOut As Outlook.MailItem
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select email address range", "KuTools For Excel", xAddress, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues)
    For Each xRgEach In xRg
        xRgVal = xRgEach.Value
        If xRgVal Like "?*@?*.?*" Then
            Set xMailOut = xOutApp.CreateItem(olMailItem)
            With xMailOut
                .To = xRgVal
                .Subject = "Test"
                .Body = "Dear " _
                      & vbNewLine & vbNewLine & _
                        "This is a test email " & _
                        "sending in Excel"
                .Display
                '.Send
            End With
        End If
    Next
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True
End Sub

以下屏幕截图可以帮助您在更改VBA代码后轻松找到差异。

运行VBA代码后,您会看到默认的Outlook签名会自动插入到已创建的电子邮件正文中,如下面的屏幕截图所示。


相关文章:


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.
    fady · 20 days ago
    Dear,
    Can someone help me with my VBA,
    I need the signature in the email created:
  • To post as a guest, your comment is unpublished.
    Bara · 3 months ago
    Hi, I would need help with my macro, I need to insert the Outlook signature under the table, could you help me with that?

    Private Sub CommandButton1_Click()


    Dim outlook As Object
    Dim newEmail As Object
    Dim xInspect As Object
    Dim pageEditor As Object

    Set outlook = CreateObject("Outlook.Application")
    Set newEmail = outlook.CreateItem(0)

    With newEmail
    .To = Sheet5.Range("F1")
    .CC = ""
    .BCC = ""
    .Subject = Sheet5.Range("B5")
    .Body = Sheet5.Range("B41")
    .display

    Set xInspect = newEmail.GetInspector
    Set pageEditor = xInspect.WordEditor

    Sheet5.Range("B6:I7").Copy

    pageEditor.Application.Selection.Start = Len(.Body)
    pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
    pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)

    .display
    Set pageEditor = Nothing
    Set xInspect = Nothing
    End With

    Set newEmail = Nothing
    Set outlook = Nothing

    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 2 months ago
      Hi Bara,
      Sorry can't help you with that. Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Kasun · 4 months ago
    Thanks a lot...
  • To post as a guest, your comment is unpublished.
    Prakash · 9 months ago
    Superb!!!!
  • To post as a guest, your comment is unpublished.
    Michael · 1 years ago
    I'm having trouble running this on excel 2016. I get a "Compile Error: User Defined Type Not Defined" message. Please help!
  • To post as a guest, your comment is unpublished.
    Maggie · 1 years ago
    If my body text is linked to pull from excel fields, the use of & .HTMLBody at the end of the string erases all of the body text and just leaves the signature.
  • To post as a guest, your comment is unpublished.
    viraj Shirsat · 1 years ago
    how to add signature if the macro is used by multiple user.
    for eg my macro will be run by 3 other persons as well. So how can the macro use the signature of the user who is running the macro.
    thanks in advance
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good Day,
      The VBA code can automatically recognize the default signature in the Outlook of the sender, and send email with his own signature through Outlook.
  • To post as a guest, your comment is unpublished.
    kostika koruni · 1 years ago
    i am trying to add the outlook signature titled "default" but cannot seem that it works.
    can you please help? I believe that my "xMailout" logic is wrong. this is my suspected faulty area.

    Private Sub CommandButton1_Click()

    Dim xOutApp As Object
    Dim xOutMail As Object
    Dim xMailBody As String
    Dim xMailOut As Outlook.MailItem
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
    xMailBody = "Greetings:" & vbNewLine & vbNewLine & _
    "This is line 1" & vbNewLine & _
    "This is line 2" & vbNewLine & _
    "This is line 3" & vbNewLine & _
    "This is line 4"
    On Error Resume Next
    With xOutMail
    .To = "Email.here.com"
    .CC = "Email.here.com"
    .Subject = "Email Title Here - " & Range("Cell#").value
    .Body = xMailBody
    . Attachments.Add ActiveWorkbook.FullName
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    With xMailOut
    .Display
    End With
    ActiveWorkbook.Save
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing
    End Sub
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good day,
      You script has been modified, please have try. Thank you.

      Private Sub CommandButton1_Click()
      Dim xOutApp As Object
      Dim xOutMail As Object
      Dim xMailBody As String
      Dim xMailOut As Outlook.MailItem
      On Error Resume Next
      Set xOutApp = CreateObject("Outlook.Application")
      Set xOutMail = xOutApp.CreateItem(0)
      xMailBody = "Greetings:" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2" & vbNewLine & _
      "This is line 3" & vbNewLine & _
      "This is line 4"
      On Error Resume Next
      With xOutMail
      .To = "Email.here.com"
      .CC = "Email.here.com"
      .Subject = "Email Title Here - " & Range("Cell#").Value
      .Body = xMailBody
      .Attachments.Add ActiveWorkbook.FullName
      Set xMailOut = xOutApp.CreateItem(olMailItem)
      With xMailOut
      .Display
      End With
      End With
      ActiveWorkbook.Save
      On Error GoTo 0
      Set xOutMail = Nothing
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    Chris · 1 years ago
    doesnt work with attachments in Office 2016
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Chris,
      The below VBA code can help you. After running the code, please select cells containing email addresses you will send emails to, and then select the files you need to attach in the email as attachments when the second dialog box pops up. And the default Outlook signature will be displayed in the email body as well. Thank you for your comment.

      Sub SendEmailToAddressInCells()
      Dim xRg As Range
      Dim xRgEach As Range
      Dim xRgVal As String
      Dim xAddress As String
      Dim xOutApp As Outlook.Application
      Dim xMailOut As Outlook.MailItem
      On Error Resume Next
      xAddress = ActiveWindow.RangeSelection.Address
      Set xRg = Application.InputBox("Please select email address range", "KuTools For Excel", xAddress, , , , , 8)
      If xRg Is Nothing Then Exit Sub
      Application.ScreenUpdating = False
      Set xOutApp = CreateObject("Outlook.Application")
      Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues)
      Set xFileDlg = Application.FileDialog(msoFileDialogFilePicker)
      If xFileDlg.Show = -1 Then
      For Each xRgEach In xRg
      xRgVal = xRgEach.Value
      If xRgVal Like "?*@?*.?*" Then
      Set xMailOut = xOutApp.CreateItem(olMailItem)
      With xMailOut
      .Display
      .To = xRgVal
      .Subject = "Test"
      .HTMLBody = "This is a test email sending in Excel" & "
      " & .HTMLBody
      For Each xFileDlgItem In xFileDlg.SelectedItems
      .Attachments.Add xFileDlgItem
      Next xFileDlgItem
      '.Send
      End With
      End If
      Next
      Set xMailOut = Nothing
      Set xOutApp = Nothing
      Application.ScreenUpdating = True
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    Favio · 1 years ago
    thank u very much, u save my life with this template :D