|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
很多人需要,最近在同事的帮助下终于完成这个,现发布出来共享一下!
Private Sub CommandButton1_Click()
On Error Resume Next
Dim rowCount, endRowNo As Integer
Dim objOutlook As New Outlook.Application
Dim objMail As MailItem
endRowNo = Cells(1, 1).CurrentRegion.Rows.Count
Set objOutlook = New Outlook.Application
Dim objData As New DataObject
For rowCount = 2 To endRowNo
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail
.To = Cells(rowCount, 1).Value '"fantasia@sina.com"
.Subject = Cells(rowCount, 2).Value '"邮件主题"
.HTMLBody = getVal(rowCount)
.Display
.Send
End With
Set objMail = Nothing
Next
Set objOutlook = 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 |
评分
-
3
查看全部评分
-
|