2012-02-29 100 views
2

我无法弄清楚如何发送超过1个工作簿为我的生活! 我知道几种不同的方式来发送电子邮件1工作簿,我把它们放在这里。电子邮件2个或多个Excel工作簿与VBA

Sub SendActiveWorkbook() 
       ActiveWorkbook.SendMail _ 
    Recipients:=Array("[email protected]", "[email protected]"), _ 
    Subject:="Write subject here"     
End Sub 

而且

Sub RouteActiveWorkbook() 
    With ActiveWorkbook 
      .HasRoutingSlip = True 
       With .RoutingSlip 
        .Delivery = xlAllAtOnce 
        .Recipients = Array("[email protected]", "[email protected]") 
        .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个工作簿的任何成功?

回答

6

希望这会有帮助吗?

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

久经考验

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 = "[email protected]" 
     .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 
+0

谢谢这正是我需要的。 – Ommit 2012-02-29 20:13:10

相关问题