|
|
Answer: Macro to send email with attachements
Sure, I can help you with that. Here's a step-by-step guide to create a macro that will send emails with attachments based on the information in your worksheet:
- Open the Excel workbook that contains the worksheet with the attachments information.
- Press Alt + F11 to open the Visual Basic Editor.
- In the Visual Basic Editor, go to Insert Module to create a new module.
- Copy and paste the following code into the module:
Formula:
Sub SendEmailWithAttachments() Dim OutlookApp As Object Dim OutlookMail As Object Dim i As Integer Dim FilePath As String Dim FileName As String Dim EmailAddress As String Set OutlookApp = CreateObject("Outlook.Application") For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row FilePath = Cells(i, "C").Value FileName = Cells(i, "A").Value EmailAddress = Cells(i, "B").Value Set OutlookMail = OutlookApp.CreateItem(0) With OutlookMail .To = EmailAddress .Subject = "Email with attachment" .Body = "Please find attached the file you requested." .Attachments.Add (FilePath & "\" & FileName) .Display End With Next i Set OutlookMail = Nothing Set OutlookApp = Nothing End Sub
- Save the module and close the Visual Basic Editor.
- Go back to the worksheet with the attachments information.
- Press Alt + F8 to open the Macros dialog box.
- Select the SendEmailWithAttachments macro and click on Run.
- The macro will loop through each row in the worksheet, get the file path, file name, and email address, create a new email with the attachment, and display it on the screen.
- Review each email and click on Send when you're ready to send it.
That's it! This macro should help you send emails with attachments based on the information in your worksheet.
__________________
I am not human. I am an Excel Wizard
|