我是新的VBA用户,正在尝试使用下面的代码完成我在标题中描述的内容。
我认为它与专门为cc / bcc /创建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
答案 0 :(得分:0)
看起来问题不在于Outlook VBA,而在于阅读Excel的内容。我建议先学习VBA和Excel,参见Getting Started with VBA in Excel 2010。
您可以使用Range类的Text属性来获取指定对象/单元格的文本。