2015-06-18 82 views
0

我是一名新的VBA用戶,正在嘗試使用下面的代碼完成我在標題中描述的內容。使用VBA根據相鄰條件發送電子郵件

我認爲這與專門爲cc/bcc /創建dims有關,但我不太確定。在一列中列出了根據特定條件已過濾的電子郵件列表,並且其旁邊的列是「」cc「」或「bcc」。如果它是空白,然後進入「到」如果是CC」它進入.CC場等等,等等

Sub SendList() 

'DIM 

    Dim olApp As Outlook.Application 
    Dim olMail As MailItem 
    Dim CurrFile As String 
    Dim emailRng As Range, cl As Range 
    Dim sTo As String 

'SET 

    Set emailRng = ActiveSheet.Range("E3:E100").SpecialCells(xlCellTypeVisible) 

    For Each cl In emailRng 

    sTo = sTo & ";" & cl.Value 

    Next 

    sTo = Mid(sTo, 2) 

    Set olApp = New Outlook.Application 
    Set olMail = olApp.CreateItem(olMailItem) 

'UPDATE WORKBOOK BEFORE SENDING 

    ActiveWorkbook.Save 
    CurrFile = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name 

'Need to find a way to automate to TO CC and BCC 

    With olMail 
     .To = sTo 
     .CC = "" 
     .BCC = "" 
     .Subject = "Audit Report XYZ" & " " & "-" & " " & Date 
     .Body = .Body & "Test" & vbCrLf & "Test2" & vbCrLf & "Test3" 
     .Attachments.Add "C:\Users\uq050e\Downloads\anyfile.xlsx" 'An audit report 
     .Display '.Send 
    End With 

    Set olMail = Nothing 
    Set olApp = Nothing 

End Sub 

回答

0

它看起來像這個問題是不是與Outlook VBA,但與閱讀Excel的內容。我建議學習VBA和Excel有點第一,看Getting Started with VBA in Excel 2010

您可以使用Range類的Text屬性來獲取指定對象/單元格中的文本。

相關問題