VBA Send PDF to multiple addresses with different subjects

Rasmussen

New Member
Joined
Jun 10, 2019
Messages
24
Hello,

I want the below code to send multiple emails with different subjects, different receivers and attachments.
Any idea how I can do this?

------------------------------------
Sub Multimail()

Set Mail_Object = CreateObject("Outlook.Application")
With Mail_Object.CreateItem(o)
.Subject = Range("A1")
.To = Range("B1")
.Body = "This is a test"
.Attachments.Add "C:\Users\EG\Documents\" & Range("C1").Value & ".pdf"
.Send
End With
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
VBA Code:
Option Explicit

Sub Send_Email()

    Dim c As Range
    Dim OutLookApp As Object
    Dim OutLookMailItem As Object
    Dim i As Integer
    On Error Resume Next
    
    For Each c In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).Cells
        Set OutLookApp = CreateObject("Outlook.application")
        Set OutLookMailItem = OutLookApp.CreateItem(0)
        With OutLookMailItem
                .To = c.Value
                .CC = c.Offset(i, 1).Value
                .Subject = c.Offset(i, 2).Value
                .HTMLBody = c.Offset(i, 3).Value
                .Attachments.Add c.Offset(i, 4).Value
                .Display
                '.Send
        End With
    Next c

End Sub

Download workbook : WORKS Bulk Email w Separate Attachments 2.xlsm
 
Upvote 0
VBA Code:
Option Explicit

Sub Send_Email()

    Dim c As Range
    Dim OutLookApp As Object
    Dim OutLookMailItem As Object
    Dim i As Integer
    On Error Resume Next
  
    For Each c In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).Cells
        Set OutLookApp = CreateObject("Outlook.application")
        Set OutLookMailItem = OutLookApp.CreateItem(0)
        With OutLookMailItem
                .To = c.Value
                .CC = c.Offset(i, 1).Value
                .Subject = c.Offset(i, 2).Value
                .HTMLBody = c.Offset(i, 3).Value
                .Attachments.Add c.Offset(i, 4).Value
                .Display
                '.Send
        End With
    Next c

End Sub

Download workbook : WORKS Bulk Email w Separate Attachments 2.xlsm
Thanks a lot.
Is there some way to show error on specific attachments or validate in another VBA before using this, in case they wasn't found? Now it just comes up with a debug, but nothing specific about which file?
 
Upvote 0

Forum statistics

Threads
1,215,731
Messages
6,126,535
Members
449,316
Latest member
sravya

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