1. 布局
2. 代码
前期绑定的话,需要勾选 Microsoft Outlook 16.0 Object Library
Option ExplicitConst SEND_Y As String = "Yes"
Const SEND_N As String = "No"
Const SEND_SELECT_ALL As String = "Select All"
Const SEND_CANCEL_ALL As String = "Cancel All"Private Sub btnSendMail_Click()Dim i, j As LongDim strSub As StringDim strBody As StringDim strSendFlag As StringDim arrFile() As StringDim strFile As StringDim objApp As ObjectDim objMail As Object'Dim objApp As New Outlook.Application'Dim objMail As MailItemSet objApp = CreateObject("Outlook.Application")For i = 4 To Range("B" & Rows.Count).End(xlUp).RowstrSendFlag = Range("B" & i).ValueIf strSendFlag = SEND_Y ThenSet objMail = objApp.CreateItem(0)On Error Resume NextWith objMail.To = Range("C" & i).Value.CC = Range("D" & i).Value.BCC = Range("E" & i).Value.Subject = Range("F" & i).Value.HTMLBody = Range("G" & i).Value''''''''''''''''''strFile = Range("H" & i).ValueIf strFile <> vbNullString ThenarrFile = Split(strFile, vbLf)End IfFor j = LBound(arrFile) To UBound(arrFile).Attachments.Add arrFile(j)Next j.Display'.SendEnd WithSet objMail = NothingOn Error GoTo 0End IfNextSet objApp = NothingMsgBox "Done."End SubPrivate Sub btnSendFlag_Click()Dim i As LongDim strSendFlag As StringColumns("B").ColumnWidth = 10btnSendFlag.Top = Range("B1").TopbtnSendFlag.Left = Range("B1").LeftbtnSendFlag.Width = Range("B1").WidthbtnSendFlag.Height = Range("B1").Height + Range("B2").HeightIf btnSendFlag.Caption = SEND_SELECT_ALL ThenstrSendFlag = SEND_YbtnSendFlag.Caption = SEND_CANCEL_ALLElsestrSendFlag = SEND_NbtnSendFlag.Caption = SEND_SELECT_ALLEnd IfFor i = 4 To Range("B" & Rows.Count).End(xlUp).RowRange("B" & i).Value = strSendFlagNext iEnd SubPrivate Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)If Target.Column = 2 ThenIf Target.Row >= 4 And Target.Row <= Range("B" & Rows.Count).End(xlUp).Row ThenIf Target.Value = SEND_Y ThenTarget.Value = SEND_NElseTarget.Value = SEND_YEnd IfEnd IfEnd IfEnd Sub