自動發送多封郵件並對應多份附件

Sub SendMail()
Dim outlookApp As Outlook.Application
Dim outlookItem As Outlook.MailItem
Dim i As Integer
Dim j As Integer
Dim p As Stringide

i = Range("B2").End(xlDown).Row

For j = 1 To i

   If j > 1 Then

    Set outlookApp = New Outlook.Application
    Set outlookItem = outlookApp.CreateItem(olMailItem)

    p = Sheet1.Range("E" & j)

    On Error GoTo Sendmail_Error
        With outlookItem
             .To = Sheet1.Range("B" & j)
             .Subject = Sheet1.Range("C" & j)
             .body = Sheet1.Range("D" & j)
             .Attachments.Add p
             .Send
        End With
   End If
Next j

SendMail_Exit:
Exit Subcode

Sendmail_Error:
MsgBox Err.Description
Resume SendMail_Exit
End Subip

相關文章
相關標籤/搜索