2012-02-29 102 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

相關問題