简体   繁体   English

VBA Excel根据通话价值发送电子邮件

[英]VBA Excel Send Email based on call value

I'm a little new to using VBA, and I was able to find the right code for most of what I'm trying to do. 我对使用VBA有点陌生,并且能够为大多数尝试要做的事情找到正确的代码。

I've created a directory of sorts in Excel, each month I have to send out separate attachments to multiple clients. 我已经在Excel中创建了一个目录,每个月我都必须向多个客户端发送单独的附件。

I have everything working, except for being able to use my saved outlook signature. 除了可以使用保存的Outlook签名之外,我已经完成所有工作。

I've found some coding for using a signature, but I don't know how to go about incorporating it with what I have. 我已经找到了一些使用签名的编码,但是我不知道如何将其与已有的签名合并。

My Code so far: 到目前为止,我的代码:

    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 

To add default signature in Outlook 在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

如果将Outlook设置为在新邮件上生成签名,则

.Body = body_ & .Body

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM