VBA Create email & attach 2 files

mholme58

New Member
Joined
Jul 27, 2010
Messages
44
Morning,

I'm hoping someone can provide a code for this. I've tried looking at previous posts but can't seem to find anything that works (or more accurately that I can get to work).

I have a spreadsheet that details some files that need to be sent and the recipients as follows
Column A = Recipients email (example@example.com; example@example.com)
Column B = Subject line
Column C = File folder directory
D = File name 1
E = File name 2

Currently I have 19 rows, but should have more in future.

I need the code to create and send the email with the 2 attachments.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Thanks. I can't add in XL2BB, so Dropbox it is. Photo also attached for reference.


I need to send the attachments in columns D & E, located in column C, to the emails in column A.
 

Attachments

  • Demo.PNG
    Demo.PNG
    103.6 KB · Views: 5
Upvote 0
Try:
VBA Code:
Sub CreateEmails()
    Application.ScreenUpdating = False
    Dim OutApp As Object, OutMail As Object, v As Variant, i As Long
    Set OutApp = CreateObject("Outlook.Application")
    v = Range("A2", Range("A" & Rows.Count).End(xlUp)).Resize(, 5).Value
    For i = LBound(v) To UBound(v)
        Set OutMail = OutApp.CreateItem(0)
        With OutMail
            .to = v(i, 1)
            .Subject = v(i, 2)
            .HTMLBody = ""
            .attachments.Add v(i, 3) & "\" & v(i, 4)
            .attachments.Add v(i, 3) & "\" & v(i, 5)
            .Display
        End With
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,221,499
Messages
6,160,169
Members
451,629
Latest member
MNexcelguy19

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