簡體   English   中英

使用Vba通過電子郵件發送2個或更多Excel工作簿

[英]Email 2 or more Excel Workbooks with Vba

我無法弄清楚如何在我的一生中發送多於一份的工作簿! 我知道通過多種方式發送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個工作簿並不能解決我的問題)。 任何人通過電子郵件發送多個工作簿都成功了嗎?

希望這可以幫助?

這是發送帶有多個附件的電子郵件的基本示例。 請根據實際情況進行修改。 如果您有任何疑問,請告訴我。 另外,在以下示例中,我也沒有處理錯誤。

經過測試

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM