【发布时间】:2015-07-07 23:48:51
【问题描述】:
我正在尝试根据单元格“A”中一个单元格中的条件从“B”列中的列表中填充电子邮件分发列表
私人子 Outlook_Email()
Dim olApp As Object
Dim olMail As Object
Dim cell As Range
Dim emailTo As String
Dim emailCC As String
Dim emailBCC As String
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
emailTo = "To"
emailCC = "CC"
emailBCC = "BCC"
For Each cell In Range("B2:B100")
If cell.Offset(-1, 0) = "To" Then emailTo = emailTo & cell.Value & ", "
ElseIf cell.Offset(-1, 0) = "CC" Then emailCC = emailCC & cell.Value & ", "
Else cell.Offset(-1, 0) = "BCC" Then emailBCC = emailBCC & cell.Value & ", "
End If
Next
Set olMail = olApp.CreateItem(0)
With olMail
.To = emailTo
.cc = emailCC
.bcc = emailBCC
.Display
End With
结束子
我得到的错误信息是:编译错误,否则循环中的 CC 行没有 If。
感谢您的帮助!
【问题讨论】: