|
Public Sub 邮件()
Dim n As Integer, i As Integer
Dim ws As Worksheet
Dim OutlookApp As Outlook.Application
Dim newMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set ws = Worksheets("sheet1")
n = ws.Range("A65536").End(xlUp).Row
For i = 2 To n
Set newMail = OutlookApp.CreateItem(olMailItem) '创建新邮件
With newMail
.Subject = "实验" '设置邮件主题
.HTMLBody = getVal(rowCount)
.To = ws.Range("A" & i) '设置收件人地址
.Send '开始发送
End With
Next i
Set ws = Nothing
Set newMail = Nothing
Set OutlookApp = Nothing
End Sub
Function getVal(ByVal j As Integer) As String
Dim i As Integer
i = 3
getVal = ""
getVal = "<table border=" & "'1'" & " style=" & "'border-right: black thin solid; border-top: black thin solid; border-left: black thin solid; border-bottom: black thin solid'" & ">"
getVal = getVal & "<tr>"
Do Until Cells(1, i) = ""
getVal = getVal & "<td align=" & "'left'" & " height=" & "'57'" & " style=" & "'width: 250px; background-color: lightskyblue; font-size: 9pt; font-family: 宋体;border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid;border-left: windowtext 0.5pt solid;border-bottom: windowtext 0.5pt solid;'" & " valign=" & "'top'" & ">"
getVal = getVal & Cells(1, i) & "</td>"
i = i + 1
Loop
getVal = getVal & "</tr>"
i = 3
Do Until Cells(j, i) = ""
getVal = getVal & "<td align=" & "'left'" & " style=" & "'width: 239px;background-color: lightskyblue; font-size: 9pt; font-family: 宋体;border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid;border-left: windowtext 0.5pt solid;border-bottom: windowtext 0.5pt solid;'" & " valign=" & "'top'" & ">"
getVal = getVal & Cells(j, i) & "</td>"
i = i + 1
Loop
getVal = getVal & "</tr></table>"
End Function
|
|