I'd like a help to finish this code.
I have a table where I have accounts with respective dates. What I want is to send an e-mail when the date in the "next day column" is less than or equal to today and then register the today date in the last day colunm and change the next day colunm to a next month date.
My final intention is to send an e-mail to notify the user when the critical day has arrived and make this as a recurrently. But I can't find a way...
I put two comments in the code below to show where I'm stuck...
What I've started is:
_____________________________________________________________
Public WrkB As Workbook
Public WrkS As Worksheet
Public Day As Range
Public Account As Range
Public LastD As Range
Public NextD As Range
Public x As Range
_____________________________________________________________
Public Sub SendEmail()
Dim servidor_smtp As String
Dim conta_autenticada As String
Dim senha_para_envio As String
Dim email_origem As String
Dim email_destino As String
Dim email_porta As Integer
Set WrkB = ThisWorkbook
Set WrkS = WrkB.Sheets("Checkouts")
Set Day = WrkS.Range("Checkouts[Day]")
Set Account = WrkS.Range("Checkouts[Account]")
Set LastD = WrkS.Range("Checkouts[LastD]")
Set NextD = WrkS.Range("Checkouts[NextD]")
With WrkS
.Select
For Each x In NextD
>!!! Here i need to check in every row the dates and use to sende the notify e-mail
Call CreateEmail
Else
End If
Next
End With
End Sub
_____________________________________________________________
Sub CreateEmail()
Dim iMsg, Cdo_Conf, Flds
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set Cdo_Conf = CreateObject("CDO.Configuration")
servidor_smtp = "smtp.gmail.com"
senha_para_envio = "1234"
email_origem = "excel@microsoft.com.br"
email_destino = "delivery@gmail.com"
email_porta = 465
email_assunto = "Checkout of "& Account & " coming!"
email_corpo = "You have 2 days for the checkout"
Cdo_Conf.Fields.Item(sch & "sendusing") = 2
Cdo_Conf.Fields.Item(sch & "smtpauthenticate") = 1
Cdo_Conf.Fields.Item(sch & "smtpserver") = servidor_smtp
Cdo_Conf.Fields.Item(sch & "smtpserverport") = email_porta
Cdo_Conf.Fields.Item(sch & "smtpconnectiontimeout") = 60
Cdo_Conf.Fields.Item(sch & "sendusername") = email_origem
Cdo_Conf.Fields.Item(sch & "sendpassword") = senha_para_envio
Cdo_Conf.Fields.Item(sch & "smtpusessl") = True
Cdo_Conf.Fields.Update
Set Cdo_Mensagem = CreateObject("CDO.Message")
Set Cdo_Mensagem.Configuration = Cdo_Conf
Cdo_Mensagem.BodyPart.Charset = "iso-8859-1"
Cdo_Mensagem.From = email_origem
Cdo_Mensagem.To = email_destino
Cdo_Mensagem.Subject = email_assunto
strBody = email_corpo
Cdo_Mensagem.HTMLBody = strBody
Cdo_Mensagem.Send
Set Cdo_Mensagem = Nothing
Set Cdo_Conf = Nothing
>!!! Here I need to change the dates, but I don't know how to use multiple variables to manipulate this
End Sub