Email a single attachment from folder of files each to a different person

后端 未结 1 1258
慢半拍i
慢半拍i 2020-12-02 02:37

I have a folder with 50 files and I have a list of 50 email addresses. Each file goes to a different email address. Is there a way to write a macro that performs this task?<

1条回答
  •  情歌与酒
    2020-12-02 02:56

    Here is quick example, assuming col A = Email, Col B = Subject & Col C = Path

    Option Explicit
    Public Sub Example()
       Dim olApp As Object
       Dim olMail As Object
       Dim olRecip As Object
       Dim olAtmt As Object
       Dim iRow As Long
       Dim Recip As String
       Dim Subject As String
       Dim Atmt As String
    
       iRow = 2
    
       Set olApp = CreateObject("Outlook.Application")
    
       Dim Sht As Worksheet
       Set Sht = ThisWorkbook.Worksheets("Sheet1")
    
       Do Until IsEmpty(Sht.Cells(iRow, 1))
    
          Recip = Sht.Cells(iRow, 1).Value
          Subject = Sht.Cells(iRow, 2).Value
          Atmt = Sht.Cells(iRow, 3).Value ' Attachment Path
    
          Set olMail = olApp.CreateItem(0)
    
          With olMail
             Set olRecip = .Recipients.Add(Recip)
            .Subject = Subject
            .Body = "Hi "
            .Display
             Set olAtmt = .Attachments.Add(Atmt)
             olRecip.Resolve
          End With
    
          iRow = iRow + 1
    
       Loop
    
       Set olApp = Nothing
    End Sub
    

    0 讨论(0)
提交回复
热议问题