Consejo: Otros idiomas son traducidos por Google. Puedes visitar el English versión de este enlace.
Iniciar sesión
x
or
x
x
Suscríbete
x

or

¿Cómo enviar un correo electrónico si la fecha de vencimiento se cumplió en Excel?

Como se muestra a continuación, si la fecha de vencimiento en la columna C es inferior o igual a 7 días (la fecha actual es 2017 / 9 / 13), envíe un recordatorio por correo electrónico al destinatario especificado en la columna A con contenido especificado en la columna B. ¿Cómo lograrlo? Este artículo proporcionará un método VBA para tratarlo en detalle.

Enviar correo electrónico si la fecha de vencimiento se cumplió con el código de VBA

Ficha Office Habilite la edición y navegación con pestañas en Office y haga su trabajo mucho más fácil ...
Kutools para Excel: la mejor herramienta de productividad de Office resolverá la mayoría de sus problemas de Excel
  • Texto automático: Cree sus gráficos, imágenes, celdas, fórmulas complejas y reutilizar ellos rápidamente en el futuro.
  • Más de características de texto 20: Extraer número de la cadena de texto; Extraer o eliminar parte de los textos; Convertir números y monedas a palabras en inglés ...
  • Herramientas de fusión: Múltiples libros de trabajo y hojas en uno; Fusionar múltiples celdas / filas / columnas y guardar datos; Combinar filas duplicadas y sumar ...
  • Herramientas divididas: Dividir datos en varias hojas en función del valor; Un libro de trabajo para múltiples archivos Excel, PDF o CSV; De una columna a varias columnas ...
  • Saltar pasta Filas ocultas / filtradas; Cuenta y suma por color de fondo; Crear lista de correo y Enviar correos electrónicos por el valor de la celda...
  • Súper filtro: Cree esquemas de filtro avanzados y aplique a cualquier hoja; Tipo de Propiedad por semana, día, frecuencia y más; Filtrar por negrita, fórmulas, comentario ...
  • Más de potentes funciones de 300; Funciona con Office 2007-2019 y 365; Soporta todos los idiomas; Fácil despliegue en compañía; Funciones completas de prueba gratuita de 60-day.

Enviar correo electrónico si la fecha de vencimiento se cumplió con el código de VBA


Haga lo siguiente para enviar un recordatorio por correo electrónico si la fecha de vencimiento se cumplió en Excel.

1. presione el otro + F11 teclas simultáneamente para abrir el Microsoft Visual Basic para aplicaciones ventana.

2. En el Microsoft Visual Basic para aplicaciones ventana, por favor haga clic recuadro > Módulo. Luego copie y pegue el código de VBA a continuación en la ventana del Módulo.

Código de VBA: envíe un correo electrónico si la fecha de vencimiento está cerrada en Excel

Public Sub CheckAndSendMail()
'Updated by Extendoffice 2018/11/22
    Dim xRgDate As Range
    Dim xRgSend As Range
    Dim xRgText As Range
    Dim xRgDone As Range
    Dim xOutApp As Object
    Dim xMailItem As Object
    Dim xLastRow As Long
    Dim vbCrLf As String
    Dim xMailBody As String
    Dim xRgDateVal As String
    Dim xRgSendVal As String
    Dim xMailSubject As String
    Dim i As Long
    On Error Resume Next
    Set xRgDate = Application.InputBox("Please select the due date column:", "KuTools For Excel", , , , , , 8)
    If xRgDate Is Nothing Then Exit Sub
    Set xRgSend = Application.InputBox("Please select the recipients?email column:", "KuTools For Excel", , , , , , 8)
    If xRgSend Is Nothing Then Exit Sub
    Set xRgText = Application.InputBox("Select the column with reminded content in your email:", "KuTools For Excel", , , , , , 8)
    If xRgText Is Nothing Then Exit Sub
    xLastRow = xRgDate.Rows.count
    Set xRgDate = xRgDate(1)
    Set xRgSend = xRgSend(1)
    Set xRgText = xRgText(1)
    Set xOutApp = CreateObject("Outlook.Application")
    For i = 1 To xLastRow
        xRgDateVal = ""
        xRgDateVal = xRgDate.Offset(i - 1).Value
        If xRgDateVal <> "" Then
        If CDate(xRgDateVal) - Date <= 7 And CDate(xRgDateVal) - Date > 0 Then
            xRgSendVal = xRgSend.Offset(i - 1).Value
            xMailSubject = xRgText.Offset(i - 1).Value & " on " & xRgDateVal
            vbCrLf = "<br><br>"
            xMailBody = "<HTML><BODY>"
            xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf
            xMailBody = xMailBody & "Text : " & xRgText.Offset(i - 1).Value & vbCrLf
            xMailBody = xMailBody & "</BODY></HTML>"
            Set xMailItem = xOutApp.CreateItem(0)
            With xMailItem
                .Subject = xMailSubject
                .To = xRgSendVal
                .HTMLBody = xMailBody
                .Display
                '.Send
            End With
            Set xMailItem = Nothing
        End If
    End If
    Next
    Set xOutApp = Nothing
End Sub

Notas: La línea Si CDate (xRgDateVal) - Fecha <= 7 Y CDate (xRgDateVal) - Fecha> 0 Luego, en el código VBA significa que la fecha de vencimiento debe ser mayor que 1 días y menor o igual a 7 días. Puedes cambiarlo como lo necesites.

3. Prensa la Tecla F5 para ejecutar el código. En la primera aparición Kutools for Excel cuadro de diálogo, seleccione el rango de columna de fecha de vencimiento y luego haga clic en OK botón. Ver captura de pantalla:

4. Entonces el segundo Kutools for Excel cuadro de diálogo emergente, seleccione el rango de columna correspondiente que contiene las direcciones de correo electrónico de los destinatarios, y haga clic en OK botón. Ver captura de pantalla:

5. En el último Kutools for Excel cuadro de diálogo, seleccione el contenido que desea mostrar en el cuerpo del correo electrónico y luego haga clic en OK botón.

A continuación, se creará un correo electrónico automáticamente con el destinatario, el asunto y el cuerpo especificados enumerados si la fecha de vencimiento en la columna C es menor o igual a 7 días. Por favor haga clic en Enviar botón para enviar el correo electrónico.

Notas:

1. Cada correo electrónico creado corresponde a una fecha de vencimiento. Por ejemplo, si hay tres fechas de vencimiento que cumplen los criterios, se crearán tres correos electrónicos automáticamente.

2. Este código no se activará si no hay fechas que cumplan con los criterios.

3. El código de VBA solo funciona cuando usa Outlook como su programa de correo electrónico.


Artículos relacionados:


Kutools for Excel: la mejor herramienta de productividad de Office aumenta su productividad en un 80%

  • Super Formula Bar (edite fácilmente varias líneas de texto y fórmula); Diseño de lectura (lee y edita fácilmente un gran número de celdas); Pegar en rango filtrado...
  • Combinar celdas / filas / columnas y mantener datos; Contenido de celdas divididas; Combinar filas duplicadas y suma / promedio... Prevenir células duplicadas; Comparar rangos...
  • Seleccione Duplicado o Único Filas; Seleccionar filas en blanco (todas las celdas están vacías); Super Find y Fuzzy Find en muchos libros de trabajo; Selección aleatoria ...
  • Copia exacta Celdas múltiples sin cambiar la referencia de fórmula; Crear referencias automáticamente a múltiples hojas; Insertar viñetas, Casillas de verificación y más ...
  • Fórmulas favoritas e insertadas rápidamente, Gamas, cuadros y cuadros; Cifrar celdas con contraseña Crear una lista de correo y enviar correos electrónicos ...
  • Extracto del texto, Agregar texto, Eliminar por posición, Eliminar espacio; Crear e imprimir subtotales de paginación; Convertir entre contenido de celdas y comentarios...
  • Súper filtro (guardar y aplicar esquemas de filtro a otras hojas); Clasificación avanzada por mes / semana / día, frecuencia y más; Filtro especial por negrita, cursiva ...
  • Combinar libros de trabajo y hojas de trabajo; Combinar tablas basadas en columnas clave; Dividir datos en varias hojas; Conversión por lotes xls, xlsx y PDF...
  • Más de potentes funciones de 300. Funciona con Office 2007-2019 y 365. Soporta todos los idiomas. Fácil despliegue en compañía. Funciones completas de prueba gratuita de 60-day.
pestaña kte 201905

Office Tab lleva la interfaz con pestañas a Office y hace que su trabajo sea mucho más fácil

  • Habilitar la edición y lectura con pestañas en Word, Excel, PowerPoint, Editor, Acceso, Visio y Proyecto.
  • Abra y cree varios documentos en nuevas pestañas de la misma ventana, en lugar de en nuevas ventanas.
  • ¡Aumenta tu productividad en un 50% y reduce cientos de clics de ratón por ti todos los días!
fondo officetab
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Jill · 5 days ago
    Hi,

    I would like to add another column in the code that allows me to write and separate message in the subject box, and another message for the email content. Can this be done?
  • To post as a guest, your comment is unpublished.
    Kayden · 11 days ago
    Hello,

    Can you modify this VBA to send automatic emails based on cell value instead of due dates? For instance, Column C2 will be a numeric value instead of a date; once it falls below XX number, then it initiates an email with subject The Park Project is due soon. Thank you!
  • To post as a guest, your comment is unpublished.
    parvana · 1 months ago
    Hello, thank a lot for the VBA code. I run it, but I have a problem. I tried several dates and realized the outlook is sending messages 1 day after the calibration date. I pu 7/14/2019
    7/15/2019
    7/16/2019
    7/17/2019
    7/18/2019
    7/19/2019
    7/20/2019
    7/21/2019 dates and after running the VBA code the excel sent me an email only for 7/19/2019; 7/20/2019; 7/21/2019 dates. Since today is 7/18/2019, it means the emails are 1 day after the calibration date. I wanted the messages to be sent the week before the due date.
  • To post as a guest, your comment is unpublished.
    David Brändle · 2 months ago
    Ich habe die VAB in der XLS Tabelle hinterlegt mit der korrekten Mail Adresse.
    Leider funktioniert es nicht. Woran kann es liegen? Gerne höre-lese ich von Ihnen. Vielen Dank.
  • To post as a guest, your comment is unpublished.
    Alex · 3 months ago
    Buenos días! ¿que modificación tendría que realizar para dejar seleccionadas las celdas con la información de fecha, texto y correo y no tener que seleccionarlas cada vez que se activa la macro?

    también me gustaría saber como introducir un CC, es decir, poder poner a otra persona en copia del correo. Gracias!
  • To post as a guest, your comment is unpublished.
    SerMFe · 3 months ago
    Hi,

    I have a question,

    If I want to select a prederterminate range of cells, how could i modify the code in this part:

    xLastRow = xRgDate.Rows.Count
    Set xRgDate = xRgDate(1)

    Toset automaticatly the cells?

    Thank you :)
  • To post as a guest, your comment is unpublished.
    LaThalia Y Echols · 4 months ago
    I am new to VBA. Is there a way to automatically run this program whenever the file is opened?
    • To post as a guest, your comment is unpublished.
      SerMFe · 3 months ago
      Yes, with


      Private Sub Workbook_Open()
      *Enter code here*
      End Sub
  • To post as a guest, your comment is unpublished.
    L Echols · 4 months ago
    Hello, I am new to VBA. Is there a way to have this program automatically run whenever the file is opened?
    • To post as a guest, your comment is unpublished.
      crystal · 4 months ago
      Hi L Echols,
      For automatically running the code when the file is opened, please double click to open the ThisWorkbook code window (locates in the left side of the Microsoft Visual Basic for Applications window) , select Workbook from the first drop-down list, and then copy the above VBA code (except the first and the last line) into the code window and paste between the given two lines. See the below attached screenshot:
      • To post as a guest, your comment is unpublished.
        Daniel Lee · 3 months ago
        This is awesome. I was wondering if there is a way to run the code without having to select the KuTools values every time? For clarification, I inputted this code and now whenever I open the workbook I still have to highlight the same columns. Is there a way to input the code to run a check on the same columns every time - as long as no edits to workbook have been made - to run the check and formulate an email based off said check? Thank you in advance.
      • To post as a guest, your comment is unpublished.
        Danny · 3 months ago
        This is awesome. I was wondering if there is a way to run the code without having to select the KuTools values every time? For clarification, I inputted this code and now whenever I open the workbook I still have to highlight the same columns. Is there a way to input the code to run a check on the same columns every time - as long as no edits to workbook have been made - to run the check and formulate an email based off said check? Thank you in advance.
        • To post as a guest, your comment is unpublished.
          crystal · 3 months ago
          Hi Danny,
          Please try the below code and change the ranges as you need.

          Public Sub CheckAndSendMail()
          'Updated by Extendoffice 2019/5/17
          Dim xRgDate As Range
          Dim xRgSend As Range
          Dim xRgText As Range
          Dim xRgDone As Range
          Dim xOutApp As Object
          Dim xMailItem As Object
          Dim xLastRow As Long
          Dim vbCrLf As String
          Dim xMailBody As String
          Dim xRgDateVal As String
          Dim xRgSendVal As String
          Dim xMailSubject As String
          Dim i As Long
          On Error Resume Next
          Set xRgDate = Range("C2: C4")
          If xRgDate Is Nothing Then Exit Sub
          Set xRgSend = Range("A2: A4")
          If xRgSend Is Nothing Then Exit Sub
          Set xRgText = Range("B2:B4")
          If xRgText Is Nothing Then Exit Sub
          xLastRow = xRgDate.Rows.Count
          Set xRgDate = xRgDate(1)
          Set xRgSend = xRgSend(1)
          Set xRgText = xRgText(1)
          Set xOutApp = CreateObject("Outlook.Application")
          For i = 1 To xLastRow
          xRgDateVal = ""
          xRgDateVal = xRgDate.Offset(i - 1).Value
          If xRgDateVal <> "" Then
          If CDate(xRgDateVal) - Date <= 7 And CDate(xRgDateVal) - Date > 0 Then
          xRgSendVal = xRgSend.Offset(i - 1).Value
          xMailSubject = xRgText.Offset(i - 1).Value & " on " & xRgDateVal
          vbCrLf = "

          "
          xMailBody = ""
          xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf
          xMailBody = xMailBody & "Text : " & xRgText.Offset(i - 1).Value & vbCrLf
          xMailBody = xMailBody & ""
          Set xMailItem = xOutApp.CreateItem(0)
          With xMailItem
          .Subject = xMailSubject
          .To = xRgSendVal
          .HTMLBody = xMailBody
          .Display
          '.Send
          End With
          Set xMailItem = Nothing
          End If
          End If
          Next
          Set xOutApp = Nothing
          End Sub
  • To post as a guest, your comment is unpublished.
    Dinesh B S · 4 months ago
    in the body i want the column a,b,c value in a table format, like the expired date once reached in the body column i want to print a,b,c cells details in table format
  • To post as a guest, your comment is unpublished.
    Sounder P · 6 months ago
    Hello Sir,

    This is very much helpful. I need 2 more enhancement in the same codes. I have to click on send button every time, it is fine as long as I have 10 email to be sent, what if I >25 emails to be sent in a single day. So please give me a code to send e-mail automatically upon selecting Due date , Recipient, Subject etc.

    Also please provide me with the code to add " CC" option as well


    Thanks

    Sounder P
    • To post as a guest, your comment is unpublished.
      crystal · 5 months ago
      Good day,
      Please try the below VBA code, hope I can help. Thanks for commenting.

      Public Sub CheckAndSendMail()
      'Updated by Extendoffice 2018/11/22
      Dim xRgDate As Range
      Dim xRgSend As Range
      Dim xRgText As Range
      Dim xRgDone As Range
      Dim xOutApp As Object
      Dim xMailItem As Object
      Dim xLastRow As Long
      Dim vbCrLf As String
      Dim xMailBody As String
      Dim xRgDateVal As String
      Dim xRgSendVal As String
      Dim xMailSubject As String
      Dim i As Long
      On Error Resume Next
      Set xRgDate = Application.InputBox("Please select the due date column:", "KuTools For Excel", , , , , , 8)
      If xRgDate Is Nothing Then Exit Sub
      Set xRgSend = Application.InputBox("Please select the recipients?email column:", "KuTools For Excel", , , , , , 8)
      If xRgSend Is Nothing Then Exit Sub
      Set xRgCC = Application.InputBox("Please select the CC recipients?email column:", "KuTools For Excel", , , , , , 8)
      If xRgCC Is Nothing Then Exit Sub
      Set xRgText = Application.InputBox("Select the column with reminded content in your email:", "KuTools For Excel", , , , , , 8)
      If xRgText Is Nothing Then Exit Sub
      xLastRow = xRgDate.Rows.Count
      Set xRgDate = xRgDate(1)
      Set xRgSend = xRgSend(1)
      Set xRgCC = xRgCC(1)
      Set xRgText = xRgText(1)
      Set xOutApp = CreateObject("Outlook.Application")
      For i = 1 To xLastRow
      xRgDateVal = ""
      xRgDateVal = xRgDate.Offset(i - 1).Value
      If xRgDateVal <> "" Then
      If CDate(xRgDateVal) - Date <= 7 And CDate(xRgDateVal) - Date > 0 Then
      xRgSendVal = xRgSend.Offset(i - 1).Value
      xRgCCVal = xRgCC.Offset(i - 1).Value
      xMailSubject = xRgText.Offset(i - 1).Value & " on " & xRgDateVal
      vbCrLf = "

      "
      xMailBody = ""
      xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf
      xMailBody = xMailBody & "Text : " & xRgText.Offset(i - 1).Value & vbCrLf
      xMailBody = xMailBody & ""
      Set xMailItem = xOutApp.CreateItem(0)
      With xMailItem
      .Subject = xMailSubject
      .To = xRgSendVal
      .Cc = xRgCCVal
      .HTMLBody = xMailBody
      .Send
      End With
      Set xMailItem = Nothing
      End If
      End If
      Next
      Set xOutApp = Nothing
      End Sub
  • To post as a guest, your comment is unpublished.
    Sam Engel · 6 months ago
    Hi, I am using a modified version of this code, and I am rather new to VBA. I was curious if there was a possibility for when the email were to be sent, that the macro would be able to mark an X, or if someone had Complete, that an email would not send. I hope this all makes sense. Any help is very greatly appreciated. Little background, I am using this tool to run a due date check at 30 days, 60 days, and overdue. I want 1 email to go out at 30 days, 1 at 60 days, and then overdue as well. I am running this off of a VB script I wrote, so that I could automate it daily. Thanks!
  • To post as a guest, your comment is unpublished.
    S. Engel · 6 months ago
    Hi, I am using a modified version of this code, and I am rather new to VBA. I was curious if there was a possibility for when the email were to be sent, that the macro would be able to mark an X, or if someone had Complete, that an email would not send. I hope this all makes sense. Any help is very greatly appreciated.

    Little background, I am using this tool to run a due date check at 30 days, 60 days, and overdue. I want 1 email to go out at 30 days, 1 at 60 days, and then overdue as well. I am running this off of a VB script I wrote, so that I could automate it daily. Thanks!
  • To post as a guest, your comment is unpublished.
    Fabrisquie Borges · 7 months ago
    Correctly, it was not with Mr. Ivan, but with Mr. Austin.
    Thank you.
  • To post as a guest, your comment is unpublished.
    Fabrisquie Borges · 7 months ago
    Hello,
    Mr. Crystal, in your last conversation with Mr. Ivan, he asked you for the code to send e-mail every time the spreadsheet is opened instead of entering the codes each time.
    I need the same code, same situation, can you help please?
  • To post as a guest, your comment is unpublished.
    Rodrigo Vicente · 9 months ago
    Thank you very much for the contribution. I would like to know how to use fixed column selection without having to use kutools? that is, leave default columns of dates, receipts, and warnings?
    • To post as a guest, your comment is unpublished.
      crystal · 9 months ago
      Good day,
      The below VBA code can help you. Please have a try.

      Public Sub CheckAndSendMail()
      'Updated by Extendoffice 2018/11/22
      Dim xRgDate As Range
      Dim xRgSend As Range
      Dim xRgText As Range
      Dim xRgDone As Range
      Dim xOutApp As Object
      Dim xMailItem As Object
      Dim xLastRow As Long
      Dim vbCrLf As String
      Dim xMailBody As String
      Dim xRgDateVal As String
      Dim xRgSendVal As String
      Dim xMailSubject As String
      Dim i As Long
      On Error Resume Next
      Set xRgDate = Range("C2:C4") 'Please reference the due date column
      If xRgDate Is Nothing Then Exit Sub
      Set xRgSend = Range("A2:A4") 'Please reference the recipients?email column
      If xRgSend Is Nothing Then Exit Sub
      Set xRgText = Range("B2:B4") Enter the column with reminded content in your email
      If xRgText Is Nothing Then Exit Sub
      xLastRow = xRgDate.Rows.count
      Set xRgDate = xRgDate(1)
      Set xRgSend = xRgSend(1)
      Set xRgText = xRgText(1)
      Set xOutApp = CreateObject("Outlook.Application")
      For i = 1 To xLastRow
      xRgDateVal = ""
      xRgDateVal = xRgDate.Offset(i - 1).Value
      If xRgDateVal <> "" Then
      If CDate(xRgDateVal) - Date <= 7 And CDate(xRgDateVal) - Date > 0 Then
      xRgSendVal = xRgSend.Offset(i - 1).Value
      xMailSubject = xRgText.Offset(i - 1).Value & " on " & xRgDateVal
      vbCrLf = "

      "
      xMailBody = ""
      xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf
      xMailBody = xMailBody & "Text : " & xRgText.Offset(i - 1).Value & vbCrLf
      xMailBody = xMailBody & ""
      Set xMailItem = xOutApp.CreateItem(0)
      With xMailItem
      .Subject = xMailSubject
      .To = xRgSendVal
      .HTMLBody = xMailBody
      .Display
      '.Send
      End With
      Set xMailItem = Nothing
      End If
      End If
      Next
      Set xOutApp = Nothing
      End Sub
      • To post as a guest, your comment is unpublished.
        niti · 7 months ago
        Dear Crytal,

        Thank for your sharing.

        I'm a beginner and I have a problem with code.

        xMailBody = ""
        xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf
        xMailBody = xMailBody & "Text : " & xRgText.Offset(i - 1).Value & vbCrLf
        xMailBody = xMailBody & ""

        The text is not go to new line.
        Could you please help.

        Thanks
        • To post as a guest, your comment is unpublished.
          crystal · 7 months ago
          Ni niti,
          You need to add the line vbCrLf = "<br><br>" in front of the coldes.
          Such as:
          vbCrLf = "<br><br>"
          xMailBody = ""
          xMailBody = xMailBody & "Dear " & xRgSendVal & vbCrLf
          xMailBody = xMailBody & "Text : " & xRgText.Offset(i - 1).Value & vbCrLf
          xMailBody = xMailBody & ""
  • To post as a guest, your comment is unpublished.
    Ivan · 9 months ago
    Hi guys,


    Macro is great but I would like to ask something - if you have someone on the list without any date how to modifiy the vba code to exclude that guy? Now the code generates e-mails even for the guys without any date.


    Thanks!
    • To post as a guest, your comment is unpublished.
      crystal · 9 months ago
      Hi Lvan,
      The code has been updated with the problem solving, please have a try. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    austin · 10 months ago
    I have got excel to send the email, but can I set this so it sends an email every time I open up excel instead of selecting the columns each time.

    I have a workbook with 24 pages so am looking to email automatically when the workbook is opened up.


    Many thanks.
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Hi,
      Do you mean check for the due date automatically across the workbook and send email when the workbook is openned up?
  • To post as a guest, your comment is unpublished.
    Dick Borman · 10 months ago
    Dont get it working. Using Office 365 so Outlook and Excel should be tight enough. Like in the post from "schou" 4 monts ago, it works up to step 5 but then nothing.
    A solution to this?
  • To post as a guest, your comment is unpublished.
    Edward Snyder · 10 months ago
    I need this to work across all worksheets in a workbook the future date will be manually entered in the same cell on every sheet and new sheets are created daily. I also need the worksheet name in the email so I will know which sheet is due
  • To post as a guest, your comment is unpublished.
    Diyaa · 1 years ago
    can we just input the details one time and the emails can be sent automatically, instead of always needing to select the columns?
    • To post as a guest, your comment is unpublished.
      crystal · 10 months ago
      Hi Diyaa,
      If you don't want to manually select the columns, please apply the below VBA code.
      Note: You onlyneed to select the due dates column after applying the code.

      Public Sub CheckAndSendMail()
      'Updated by Extendoffice 2017/9/14
      Dim xRgDate As Range
      Dim xRgSend As Range
      Dim xRgText As Range
      Dim xRgDone As Range
      Dim xOutApp As Object
      Dim xMailItem As Object
      Dim xLastRow As Long
      Dim vbCrLf As String
      Dim xMailBody As String
      Dim xRgDateVal As String
      Dim xRgSendVal As String
      Dim xMailSubject As String
      Dim I As Long
      On Error Resume Next
      Set xRgDate = Application.InputBox("Please select the due date column:", "KuTools For Excel", , , , , , 8)
      If xRgDate Is Nothing Then Exit Sub
      xLastRow = xRgDate.Rows.Count
      Set xRgDate = xRgDate(1)
      Set xRgSend = xRgSend(1)
      Set xRgText = xRgText(1)
      Set xOutApp = CreateObject("Outlook.Application")
      For I = 1 To xLastRow
      xRgDateVal = xRgDate.Offset(I - 1).Value
      If CDate(xRgDateVal) - Date <= 7 And CDate(xRgDateVal) - Date > 0 Then
      xRgSendVal = xRgSend.Offset(I - 1).Value
      xMailSubject = xRgText.Offset(I - 1).Value & " on " & xRgDateVal
      vbCrLf = "

      "
      xMailBody = "Hi there" & vbNewLine & vbNewLine & _
      "This is line 1" & vbNewLine & _
      "This is line 2"
      Set xMailItem = xOutApp.CreateItem(0)
      With xMailItem
      .To = "Email Address"
      .CC = ""
      .BCC = ""
      .Subject = "send by cell value test"
      .Body = xMailBody
      .Display 'or use .Send
      End With
      Set xMailItem = Nothing
      End If
      Next
      Set xOutApp = Nothing
      End Sub
      • To post as a guest, your comment is unpublished.
        Thomas · 5 months ago
        Hello,
        I'm also pretty much of a beginner and I would like to ask another question for your great Sub.

        How can I send an email only if a certain mail-adress is in the regarding cell?

        I need this, because in my excel-tool i implemented some buttons for each person, who needs a reminder.

        Thank you very much in advance!!

        Thomas
  • To post as a guest, your comment is unpublished.
    Robert · 1 years ago
    This code froze my excel program when I ran it. Is it memory intensive?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Robert,
      The problem you mentioned does not appear in my case. May I have your Office version?
  • To post as a guest, your comment is unpublished.
    Maria · 1 years ago
    Me viene muy bien gracias por el aporte, solo me falta como puedo hacerlo automaticamente sin necesidad de hacerlo manualmente el envio del correo.
  • To post as a guest, your comment is unpublished.
    schou · 1 years ago
    I used your VBA code for sending emails based on a cell value but it doesn’t work.
    Everything up until step 5 works but no email is sent. Can anyone help me with this?
  • To post as a guest, your comment is unpublished.
    Brandon Pillay · 1 years ago
    Thank you for sharing.


    How would you add Cc inputs or multiple recipients?
    • To post as a guest, your comment is unpublished.
      schou · 1 years ago
      Hi Brandon,

      Sorry to comment on your post without an answer but were you able to get the VBA code to send an email?