VBA for sending emails with individual attachments

ACORN 356

New Member
Joined
Oct 10, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,
I've written the following code for sending emails with individual attachments. The code cannot execute the attachment part. Without it, the code works fine.
Could you please have a look and tell me how to modify the code in order for the attachments to work.

Sub Send_Bulk_Email()

Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("name")
Dim i As Integer

Dim OA As Object
Dim msg As Object
Dim AttachmentFolder As String
Dim AttachmentFile As String = "C:\Users\jenny.abbott\Documents\"

Set OA = CreateObject("Outlook.application")
Dim lastRow As Integer
lastRow = Application.CountA(ws.Range("A:A"))

For i = 2 To lastRow
Set msg = OA.createItem(0)
msg.To = ws.Range("A" & i).Value
msg.CC = ws.Range("B" & i).Value
msg.BCC = ws.Range("C" & i).Value
msg.Subject = ws.Range("D" & i).Value
msg.Body = ws.Range("E" & i).Value

If ws.Range("F" & i).Value <> "" Then
msg.attachments.Add.ws.Range("F" & i).Value
End If


msg.display
ws.Range("G" & i).Value = "Sent"
Next i

MsgBox "Successfully Sent"

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top