我已经编写了 90% 的 VBA 代码,只需要添加以下内容。我的宏几乎可以运行,如果语句,并且如果某个条件适用,它将通过电子邮件将其发送到某个地址。我需要它做的是运行 if 语句,如果它满足特定条件,则通过电子邮件将其发送到 4-5 封电子邮件列表(可能更多),该列表位于同一工作簿中,但标题为“电子邮件列表”的不同选项卡”。
你可以忽略上面的部分,这是我目前正在做的。
这是更新的代码。请告知,因为有 8 个部分,那么我将如何转移您为接下来的 7 个提出的电子邮件代码?在此先感谢您,非常感谢您的所有帮助。
Sub Send_Range()
Dim row As Long
Dim col As Long
Dim rCell As Range
Dim SendTo As String
Dim i As Long
row = Sheets("Email List").UsedRange.Rows.Count
col = Sheets("Email List").UsedRange.Columns.Count
If Not IsEmpty(Range("B4")) Then
With Sheets("Email List")
For Each rCell In .Range(.Cells(1, 1), .Cells(1, col))
If rCell.Value <> "" Then
For i = 3 To row
If .Cells(i, rCell.Column).Value <> "" Then
SendTo = SendTo & .Cells(i, rCell.Column + 1).Value & ";"
End If
Next
End If
Next
End With
End If
If IsEmpty(Range("B4")) Then
Else
ActiveSheet.Range("a3", ActiveSheet.Range("e3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = SendTo
.Item.Subject = "Allocations - Barclays" & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
row = Sheets("Email List").UsedRange.Rows.Count
col = Sheets("Email List").UsedRange.Columns.Count
If Not IsEmpty(Range("B4")) Then
With Sheets("Email List")
For Each rCell In .Range(.Cells(1, 1), .Cells(1, col))
If rCell.Value <> "" Then
For i = 3 To row
If .Cells(i, rCell.Column).Value <> "" Then
SendTo = SendTo & .Cells(i, rCell.Column + 1).Value & ";"
End If
Next
End If
Next
End With
End If
If IsEmpty(Range("H4")) Then
Else
ActiveSheet.Range("G3", ActiveSheet.Range("K3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "alulla@bluemountaincapital.com" & "; alulla92@outlook.com"
.Item.Subject = "Allocations - BNP" & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
If IsEmpty(Range("N4")) Then
Else
ActiveSheet.Range("M3", ActiveSheet.Range("Q3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "alulla@bluemountaincapital.com" & "; alulla92@outlook.com"
.Item.Subject = "Allocations - CITINY" & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
If IsEmpty(Range("T4")) Then
Else
ActiveSheet.Range("S3", ActiveSheet.Range("W3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "alulla@bluemountaincapital.com" & "; alulla92@outlook.com"
.Item.Subject = "Allocations - CSFB" & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
If IsEmpty(Range("Z4")) Then
Else
ActiveSheet.Range("Y3", ActiveSheet.Range("AC3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "alulla@bluemountaincapital.com" & "; alulla92@outlook.com"
.Item.Subject = "Allocations - DB" & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
If IsEmpty(Range("AF4")) Then
Else
ActiveSheet.Range("AE3", ActiveSheet.Range("AI3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "alulla@bluemountaincapital.com" & "; alulla92@outlook.com"
.Item.Subject = "Allocations - JPM" & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
If IsEmpty(Range("AL4")) Then
Else
ActiveSheet.Range("AK3", ActiveSheet.Range("AO3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "alulla@bluemountaincapital.com" & "; alulla92@outlook.com"
.Item.Subject = "Allocations - MS" & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
If IsEmpty(Range("AR4")) Then
Else
ActiveSheet.Range("AQ3", ActiveSheet.Range("AU3").End(xlDown)).Select
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Item.To = "alulla@bluemountaincapital.com" & "; alulla92@outlook.com"
.Item.Subject = "Allocations - " & Format(Date, " mm/dd/yyyy")
.Item.Send
End With
End If
End Sub