2个或更多的Excel工作簿与VBA的电子邮件

我不知道如何发送超过1个工作簿为我的生活! 我知道有两种不同的方式来发送1个工作簿,我把它们放在这里。

Sub SendActiveWorkbook() ActiveWorkbook.SendMail _ Recipients:=Array("MyEmail@123.com", "AnotherEmail@123.com"), _ Subject:="Write subject here" End Sub 

 Sub RouteActiveWorkbook() With ActiveWorkbook .HasRoutingSlip = True With .RoutingSlip .Delivery = xlAllAtOnce .Recipients = Array("MyEmail@123.com", "AnotherEmail@123.com") .Subject = "CSAM Lux BIEO and BCF breakdown" .Message = "Attached are the breakdowns as of " & Date End With .Route End With End Sub 

我似乎只能在给定的电子邮件中发送1个工作簿。 (这不会解决我的问题,使我的2工作簿到1工作簿)。 任何人都可以通过电子邮件发送超过1个工作簿?

希望这可以帮助?

这是发送超过1个附件的电子邮件的基本示例。 请根据实际情况修改。 如果您有任何问题,请告诉我。 在下面的例子中我也没有关心error handling。

尝试和testing

 Option Explicit Sub Sample() Dim OutApp As Object Dim OutMail As Object Dim MyFileList(1) As String Dim i As Long '~~> Change/Add the file names here MyFileList(0) = "C:\Sample1.xlsm" MyFileList(1) = "C:\Sample2.xlsm" Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) With OutMail .To = "MyEmail@123.com" .Subject = "Example for attaching 2 files" .Body = "Hi Ommit :)" For i = LBound(MyFileList) To UBound(MyFileList) .Attachments.Add MyFileList(i) Next i .Display End With End Sub