邮件表(S)在Microsoft Excel中使用VBA一人或多人
添加新工作表,将工作表名称更改为mail。
您要发送的每封邮件都将使用3列。
。在A列中-输入您要发送的工作表名称。
。在B列中-输入电子邮件地址。
。在C列中-主题标题显示在电子邮件的顶部。
A:C列输入第一封邮件的信息,第二列可以使用D:F列。
您可以通过这种方式发送85种不同的电子邮件(85 * 3 = 255列)。
Sub Mail_sheets() Dim MyArr As Variant Dim last As Long Dim shname As Long Dim a As Integer Dim Arr() As String Dim N As Integer Dim strdate As String For a = 1 To 253 Step 3 If ThisWorkbook.Sheets("mail").Cells(1, a).Value = "" Then Exit Sub Application.ScreenUpdating = False last = ThisWorkbook.Sheets("mail").Cells(Rows.Count, a).End(xlUp).Row N = 0 For shname = 1 To last N = N + 1 ReDim Preserve Arr(1 To N) Arr(N) = ThisWorkbook.Sheets("mail").Cells(shname, a).Value Next shname ThisWorkbook.Worksheets(Arr).Copy strdate = Format(Date, "dd-mm-yy") & " " & Format(Time, "h-mm-ss") ActiveWorkbook.SaveAs "Part of " & ThisWorkbook.Name _ & " " & strdate & ".xls" With ThisWorkbook.Sheets("mail") MyArr = .Range(.Cells(1, a + 1), .Cells(Rows.Count, a + 1).End(xlUp)) End With ActiveWorkbook.SendMail MyArr, ThisWorkbook.Sheets("mail").Cells(1, a + 2).Value ActiveWorkbook.ChangeFileAccess xlReadOnly Kill ActiveWorkbook.FullName ActiveWorkbook.Close False Application.ScreenUpdating = True Next a End Sub