Estoy usando el código VBA para enviar varios correos electrónicos desde una hoja de Excel que se parece al siguiente ejemplo:
Ejemplo de hoja de Excel
Hasta ahora, puedo usar el código para generar un correo electrónico separado para cada dirección de correo electrónico en la Columna C con un archivo adjunto. Mi código está debajo: estoy buscando agregar un código que me permita hacer lo siguiente:
Cada fila en la hoja de Excel debe generar un correo electrónico separado usando la dirección de correo electrónico en la columna C, la fecha en la columna D y el archivo adjunto en la columna E.
Sub CreateEmails() Dim sourceWorksheet As Worksheet Set sourceWorksheet = Worksheets("Sheet1") Dim lastRow As Long With sourceWorksheet lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row End With Dim OutlookApp As Object Set OutlookApp = CreateObject("Outlook.Application") Dim rowIndex As Long For rowIndex = 2 To lastRow 'start at the second row Dim MItem As Object Set MItem = OutlookApp.CreateItem(0) With MItem .To = sourceWorksheet.Cells(rowIndex, "C").Value 'Will pull in all email address in Row C as separate emails .Subject = "Subject Here" .Attachments.Add “first attachment link goes here" .htmlBody = "<p><font face = ""Calibri(Body)"" font size=""3"" color=""black"">Good afternoon, </p>" & _ "<p><font face = ""Calibri(Body)"" font size=""3"" color=""black""><strong>Please review the attached and return by" & DueDate & ". </strong> </p>"& .htmlBody .display End With Next rowIndex End Subsuponga que el resto del código funciona, simplemente actualice el bloque with a:
With MItem .To = sourceWorksheet.Cells(RowIndex, 3).Value .Subject = "Subject Here" If Cells(RowIndex, 5) <> "" Then .Attachments.Add Cells(RowIndex, 5).Value If Cells(RowIndex, 6) <> "" Then .Attachments.Add Cells(RowIndex, 6).Value .HTMLBody = "<font face = ""Calibri(Body)"" font size=""3"" color=""black""><p>Good afternoon, </p>" & _ "<p><strong>Please review the attached and return by " & Cells(RowIndex, 4) & ". </strong> </p></font>" & .HTMLBody .Display End With