提示:其他語言是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解決了您的大多數問題,並使您的生產率提高了80%
  • 重用任何東西: 將最常用或最複雜的公式,圖表和其他任何內容添加到您的收藏夾中,並在將來快速重複使用它們。
  • 超過20文本功能: 從文本字符串中提取數字; 提取或刪除部分文字; 將數字和貨幣轉換為英文單詞。
  • 合併工具:將多個工作簿和工作表合二為一; 合併多個單元格/行/列,而不會丟失數據; 合併重複的行和總和。
  • 拆分工具:根據價值將數據分割成多個工作表; 一本工作簿可轉換為多個Excel,PDF或CSV文件; 一列到多列。
  • 粘貼跳過 隱藏/過濾行; 數和總和 按背景顏色; 將個性化電子郵件批量發送給多個收件人。
  • 超級過濾器: 創建高級過濾方案並應用於任何工作表; 分類 按週,日,頻率等; 過濾 通過大膽,公式,評論......
  • 超過300強大的功能; 與Office 2007-2019和365一起使用; 支持所有語言; 在您的企業或組織中輕鬆部署。

通過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。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
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.
    Jay Kanojiya · 1 months ago
    Thanks to you, I can add signature now but then it removes spaces between paragraph of text. Please Can you Help me ?


    Sub helloworld()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim cell As Range
    Dim Path As String
    Path = Application.ActiveWorkbook.Path
    Set OutApp = CreateObject("Outlook.Application")

    For Each cell In Range("C4:C6")
    Set OutMail = OutApp.CreateItem(0)
    With OutMail
    .Display
    .To = cell.Value
    .Subject = Cells(cell.Row, "D").Value
    .HTMLBody = "Dear " & Cells(cell.Row, "B").Value & "," _
    & vbNewLine & vbNewLine & _
    "Warm Greetings" _
    & vbNewLine & vbNewLine & _
    "We, JK Overseas, would like to take an opportunity and introduce our company J K Overseas, which is involved in the salt business for the last 3 years. We are currently strong in domestic and expanding overseas. We are the supplier of Edible Salt, Water Softening Salt, De-icing Salt, Industrial Salt" & "." _
    & vbNewLine & vbNewLine & _
    "We have a tie-up with large scale manufacturers in India and procure from them quality Salt and exports. So, we are looking for a reliable expert importer as well as distributor agent to make a long-term Business with mutual benefit" & "." _
    & vbNewLine & vbNewLine & _
    "Please contact us with your requirement or for any other inquiries you may have. We provide reliable logistics and on-time delivery. We are confident that our prices being most competitive will match your expectations" & "." _
    & vbNewLine & vbNewLine & _
    .HTMLBody

    '.Send
    End With
    Next cell
    End Sub
  • To post as a guest, your comment is unpublished.
    fady · 3 months 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 · 6 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 · 5 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 · 7 months ago
    Thanks a lot...
  • To post as a guest, your comment is unpublished.
    Prakash · 11 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 · 2 years ago
    thank u very much, u save my life with this template :D