VBA to Email diffrent email addresses and add dynamic excel file attachment

russellheidi

New Member
Joined
Oct 26, 2014
Messages
4
Hi All


Could someone please help me write a VBA to automatically email a list of emailaddresses in Column A and add an Excelfile attachment for that email address which is in Column D. Column C is the root directoryfor where all the files are kept.


I have a low understanding of VBA, but an idea. So any supportwould be welcome with any instructions you think I may need.

See picture below as an example, but I am happy to changelayout if required.

Thanks Russ
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You can use this small application to send several emails with different Subject and with different files.

https://www.dropbox.com/s/a0dpmr57n2hp70v/Email5c sample.xlsm?dl=0


Code:
Sub Enviar_Correos()
'---
'  
'---
    '***Macro to send email
    col = Range("H1").Column
    For i = 2 To Range("B" & Rows.Count).End(xlUp).Row
        Set dam = CreateObject("Outlook.Application").CreateItem(0)
        '
        dam.To = Range("B" & i).Value           'To
        dam.Cc = Range("C" & i).Value           'With copy
        dam.Bcc = Range("D" & i).Value          'hide copy
        dam.Subject = Range("E" & i).Value      'subject
        dam.Body = Range("F" & i).Value         'body
        '
        For j = col To Cells(i, Columns.Count).End(xlToLeft).Column
            archivo = Cells(i, j).Value
            If archivo <> "" Then dam.Attachments.Add archivo
        Next
        dam.Send                                send
        'dam.Display                             'show
    Next
    MsgBox "End", vbInformation, "Regards"
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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