Looping through a set range and email an attachment

KNKN9

Board Regular
Joined
Mar 27, 2017
Messages
92
Hi,

I am struggling to loop through my sent range to send an email via outlook with attachments.

so far I have

coloum N
email 1
email 2
email 3
email 4
email 5

Code:
Sub projtodat ()Dim OutApp As Object
Dim OutMail As Object
Dim Rng As Range
Set Rng = Range(Range("N2"), Range("N2").End(xlDown))
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
        .to = Rng
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hi there"
        .Attachments.Add ("C:\Users\naomie.kiwutila\Documents\ASPAC\Hong_Kong\ASPAC -  BAT 2017 Quarterly InScope & Adhoc Fee Report Hong Kong (TW).xlsx")
       .display  
    End With
    On Error GoTo 0


    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
.

So I need the email to get sent to every email in my set range.

Many Thanks in advanced !!

Naomie
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Naomie

You need a semi-colon separated list of recipients, try this.
Code:
Sub projtodat()
Dim OutApp As Object
Dim OutMail As Object
Dim Rng As Range
Dim strRecipients As Variant

    Set Rng = Range(Range("N2"), Range("N2").End(xlDown))
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    On Error Resume Next

    strRecipients = Join(Application.Transpose(Rng.Value), ";")
    
    With OutMail
        .To = strRecipients
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hi there"
        .Attachments.Add ("C:\Users\naomie.kiwutila\Documents\ASPAC\Hong_Kong\ASPAC -  BAT 2017 Quarterly InScope & Adhoc Fee Report Hong Kong (TW).xlsx")
        .Display
    End With
    
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,860
Members
449,194
Latest member
HellScout

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