VBA Excel基于调用值发送电子邮件
我对使用VBA有点陌生,我能够为我正在尝试做的大部分工作找到正确的代码 我在Excel中创建了一个目录,每个月我都要向多个客户端发送单独的附件 除了能够使用保存的outlook签名之外,我的一切都正常工作 我找到了一些使用签名的代码,但我不知道如何将它与我所拥有的结合起来 到目前为止,我的代码是:VBA Excel基于调用值发送电子邮件,vba,excel,Vba,Excel,我对使用VBA有点陌生,我能够为我正在尝试做的大部分工作找到正确的代码 我在Excel中创建了一个目录,每个月我都要向多个客户端发送单独的附件 除了能够使用保存的outlook签名之外,我的一切都正常工作 我找到了一些使用签名的代码,但我不知道如何将它与我所拥有的结合起来 到目前为止,我的代码是: Sub SendEmail() Dim OutlookApp As Object Dim MItem As Object Dim cell As Range
Sub SendEmail()
Dim OutlookApp As Object
Dim MItem As Object
Dim cell As Range
Dim email_ As String
Dim cc_ As String
Dim subject_ As String
Dim body_ As String
Dim attach_ As String
'Create Outlook object
Set OutlookApp = CreateObject("Outlook.Application")
'Loop through the rows
For Each cell In Columns("a").Cells.SpecialCells(xlCellTypeConstants)
email_ = cell.Value
subject_ = cell.Offset(0, 1).Value
body_ = cell.Offset(0, 2).Value
cc_ = cell.Offset(0, 3).Value
attach_ = cell.Offset(0, 4).Value
'Create Mail Item and send it
Set MItem = OutlookApp.CreateItem(0)
With MItem
.To = email_
.CC = cc_
.Subject = subject_
.Body = body_
.Attachments.Add attach_
'.Display
End With
MItem.Send
Next
End Sub
在Outlook中添加默认签名的步骤
'Create Mail Item and send it
Set MItem = OutlookApp.CreateItem(0)
With MItem '<-----Added
.Display '<-----Added
End With '<-----Added
signature = MItem.body '<-----Added
With MItem
.To = email_
.CC = cc_
.Subject = subject_
.body = body_ & vbNewLine & signature ' <-----Added (& vbNewLine & signature)
.Attachments.Add attach_
'.Display
End With
”创建邮件项目并发送
设置MItem=OutlookApp.CreateItem(0)
使用MItem'如果Outlook设置为在新邮件上生成签名,则
.Body = body_ & .Body