gpt4 book ai didi

excel - 将文件签名和 Excel 文件数据添加到 Outlook 电子邮件

转载 作者:行者123 更新时间:2023-12-03 02:28:26 28 4
gpt4 key购买 nike

我从 SAP 下载了 1000 多个客户的列表。我有一个宏用于发送月度报表(有关未清发票或未结案件的 pdf)。

我的宏从 A 列获取电子邮件地址,下一列是电子邮件主题,最后一列是电子邮件正文:

Sub SendMail()

Dim objOutlook As Object
Dim objMail As Object
Dim ws As Worksheet

Set objOutlook = CreateObject("Outlook.Application")
Set ws = ActiveSheet
For Each cell In ws.Range("A2:A1000")
Set objMail = objOutlook.CreateItem(0)
With objMail
.To = cell.Value
.Subject = cell.Offset(0, 1).Value
.Body = cell.Offset(0, 2).Value
.Attachments.Add cell.Offset(0, 3).Value
'display will show you email before it is sent, replace it with "send" and it will sent email without displaying
.send
End With
Set objMail = Nothing
Next cell

Set ws = Nothing
Set objOutlook = Nothing

End Sub

它有效,但我想调整它。

  1. 如何添加签名,例如存储在桌面上的 .htm 中的签名(更改签名以便我的所有同事个性化电子邮件)。
  2. 电子邮件包含来自 SAP 报告的延迟发票列表 - 客户有特定的 SAP 编号。
    example

我需要将包含特定客户编号(名为帐户)的所有未清项目添加到电子邮件中。

最佳答案

关于第 1 部分,您可以按照此处的说明将 HTML 转换为 Outlook 模板文件 (.oft):

http://smallbusiness.chron.com/convert-html-oft-52249.html

然后可以按照以下文档使用 Application.CreateItemFromTemplate 方法使用该模板文件:

https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/application-createitemfromtemplate-method-outlook

关于第 2 部分,要在电子邮件中包含表格数据,只需使用如下所示的内容:

Dim OutApp As Object: Set OutApp  = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0) ' or use the template method specified in pt 1.

Dim html As String: html = "<html><body><table>"
Dim row As String

' the two lines below should be changed to include data from your excel
' table when filtered. Repeat the two lines below for the rows as required

row = "<tr><td> .... </td></tr>"
html = html & row

' once the rows are processed, close off the html tags

html = html & "</table></body></html>"

With OutMail
.To = "email_address@email.com"
.CC = ""
.BCC = ""
.HTMLBody = html
.BodyFormat = olFormatHTML
.Display ' or .Send
End With

关于excel - 将文件签名和 Excel 文件数据添加到 Outlook 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45612336/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com