2015-06-12 99 views
0

我對使用VBA有點新,而且我能夠找到正在嘗試做的大部分工作的正確代碼。VBA Excel根據通話價值發送電子郵件

我已經在Excel中創建了一個排序目錄,每個月我都必須發送單獨的附件給多個客戶端。

我有一切工作,除了能夠使用我保存的Outlook簽名。

我發現了一些使用簽名的編碼,但我不知道如何將它與我所擁有的相結合。

到目前爲止我的代碼:

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 

回答

0

要在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 
0

如果Outlook設置爲產生新的郵件,然後

.Body = body_ & .Body 
簽名