0

我是一个新的 VBA 用户,正在尝试使用下面的代码完成我在标题中描述的内容。

我认为这与专门为 cc/bcc/and to 创建 dims 有关,但我不太确定。在一列中是已根据特定条件过滤的电子邮件列表,在它旁边的列中是“”“cc”或“bcc”。如果它是空白的,那么它会进入“to”,如果它是 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
4

1 回答 1

0

看起来问题不在于 Outlook VBA,而在于阅读 Excel 的内容。我建议先学习一下 VBA 和 Excel,请参阅Excel 2010 中的 VBA 入门

您可以使用 Range 类的Text属性来获取指定对象/单元格的文本。

于 2015-06-18T16:49:42.880 回答