Doubts in excel

Asked

Viewed 76 times

1

I’m creating a macro where you send emails, but I’m stuck in a process.

I wonder if it is possible to create a column where I select a reason for pending, for example "lack of rg" that when selected, it brings a script ready and automatically inserted in the body of the email.

I’m using a very simple code I found on the net..

Baseado no código disponibilizado em http://guiadoexcel.com.br/
Function EnviaEmail()
Dim iMsg, iConf, Flds

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
'Configura o smtp
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
'Configura a porta de envio de email
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
'Configura o email do remetente
Flds.Item(schema & "sendusername") = "[email protected]"
'Configura a senha do email remetente
Flds.Item(schema & "sendpassword") = "senha do seu e-mail"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

With iMsg
   'Email do destinatário
   .To = "[email protected]"
   'Seu email
   .From = [email protected]
   'Título do email
   .Subject = "Isto é um teste de Envio de e-mail"
   'Mensagem do e-mail, você pode enviar formatado em HTML
   .HTMLBody = "Mensagem enviada com o gmail"
   'Seu nome ou apelido
   .Sender = "Teste"
   'Nome da sua organização
   .Organization = "Aprender Excel"
   'e-mail de responder para
   .ReplyTo = "[email protected]"
   'Anexo a ser enviado na mensagem. Retire a aspa da linha abaixo e coloque o endereço do arquivo
   .AddAttachment ("c:/fatura.txt")
   Set .Configuration = iConf
   .Send
End With

Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Function

Sub disparar()
   EnviaEmail
   MsgBox "O e-mail foi disparado com sucesso!", vbOKOnly, "e-mail enviado"
End Sub
  • The problem was not described. There is something wrong with the code?

  • It is possible, you can perform in several ways. One of them is with the use of forms (Userform).

  • Another way would be to use a simple If. If it is "missing of rg" it calls a function that inserts such a script, for example. (P.s. This code was taken from my website, look at my email there euhuehe Thanks for the audience)

  • 2

    Good friends, I just wanted to know if it was possible to be done. Now I will go after the media. Yes Max, I took it from your site even, it helped a lot! Thanks haha

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.