Usuário com melhor resposta
Enviar e-mail de Alerta pelo Excel

Pergunta
-
Gostaria de verificar se possível o excel enviar um e-mail de alerta toda vez que fosse registrado um ocorrência em uma planilha sendo que as informações só são salvas e enviadas para um banco de dado após clicar em um botão salve que eu fiz em macro.
Seria o envio para um e-mail fixo avisando que uma nova ocorrência foi registrada. um um texto sim como "Uma nossa ocorrência foi registrada no SAC"
Obrigada!
Respostas
-
Algo como:
Sub Salvar() Sheets("Planilha de Acompalhamento").Select Sheets("Planilha de Acompalhamento").Name = "Planilha de Acompalhamento" Range("A3").Select Range(Selection, Selection.End(xlToRight)).Select Selection.Copy Range("A4").Select Range(Selection, Selection.End(xlToRight)).Select Range("A4:AE4").Select Range("AE4").Activate Selection.Insert Shift:=xlDown Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("D14").Select Application.CutCopyMode = False Sheets("Planilha de Acompalhamento").Select Rows("3:3").Select Selection.EntireRow.Hidden = True Sheets("Rel_Imprimir").Select EMail_Automátic End Sub Sub EMail_Automátic() '========================================================== 'PARA REMESSA DE E-MAIL AUTOMÁTICO DE DENTRO DAS APLICAÇÕES '========================================================== Dim OutApp As Object Dim OutMail As Object Dim Texto As String Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) Texto = "Há um novo registro de ocorrência no SAC" & vbCrLf & _ "Nº: " & Range("B10").Value & vbCrLf & "Aberto em: " & Range("G5").Value & vbCrLf & _ "Por: " & Range("B5").Value & vbCrLf & _ "Relato: " & Range("B23").Value With OutMail .To = "evelyn@xxxxx.com.br" .CC = "" .BCC = "" .Subject = "Novo Registro de Ocorrência no SAC" .Body = Texto .Display 'Utilize Send para enviar o email sem abrir o Outlook End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub
http://www.ambienteoffice.com.br - http://www.clarian.com.br
- Marcado como Resposta Felipe Costa GualbertoMVP, Moderator segunda-feira, 4 de julho de 2016 13:56
-
Olá Felipe, conseguir!
Segue resolução:
Sub Salvar()
RelImprimir.Calculate
Acompanhamento.Calculate
Acompanhamento.Rows("4:4").Insert Shift:=xlDown
Acompanhamento.Range("A4:AE4").Value = Acompanhamento.Range("A3:AE3").Value
MsgBox "Registros salvos com sucesso!" & vbNewLine & "Aperte em OK para sair do aviso", , "Aviso!"
Call EMail_Automático
End Sub
Sub EMail_Automático()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "evelyn@v.com.br"
.CC = ""
.BCC = ""
.Subject = "Novo Registro de Ocorrência no SAC"
.Body = "Há um novo registro de ocorrência no SAC" & vbCrLf & _
"Nº: " & Range("B10").Value & vbCrLf & _
"Aberto em: " & Range("G5").Value & vbCrLf & _
"Por: " & Range("B5").Value & vbCrLf & _
"Relato: " & Range("B23").Value
.Send 'Utilize Send para enviar o email sem abrir o Outlook ou ultilize Display para ve o e-mail antes de enviar
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Muito Obrigada pela paciência e dedicação!
- Marcado como Resposta Felipe Costa GualbertoMVP, Moderator segunda-feira, 4 de julho de 2016 13:56
Todas as Respostas
-
-
Felipe,
A planilha registra uma ocorrência após clicar no botão salvar que fiz usando macro.
Após testar alguns códigos eu conseguir não exatamente o que eu queria, eu gostaria que o If funcionasse toda vez que o botão fosse acionado.
Como eu faço para mencionar esse botão no If? já tentei varias maneira e não esta dando certo.
Ex:
Sub EMail_Automático()
Dim olApp As Object, olMail As Object
If CommandbuttonSalva_Click Then (Se eu clicar no botão "Salvar" então)
Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)Conseguir explicar direito?
Obrigada!
-
Você tem que chamar a rotina EMail_Automático ao clicar no botão de comando CommandbuttonSalva. Já experimentou seguir essa lógica?
http://www.ambienteoffice.com.br - http://www.clarian.com.br
- Editado Felipe Costa GualbertoMVP, Moderator sexta-feira, 24 de junho de 2016 13:59
-
Eu to me ariscando no VBA agora e não sei nada praticamente. Você poderia me mostra como seria?
Segue o código:
Sub EMail_Automátic()
'==========================================================
'PARA REMESSA DE E-MAIL AUTOMÁTICO DE DENTRO DAS APLICAÇÕES
'==========================================================
Dim OutApp As Object
Dim OutMail As Object
Dim texto As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
If commandSalvar_click Then
texto = "Há um novo registro de ocorrência no SAC" & vbCrLf & _
"Nº: " & Range("B10").value & vbCrLf & "Aberto em: " & Range("G5").value & vbCrLf & _
"Por: " & Range("B5").value & vbCrLf & _
"Relato: " & Range("B23").value
End If
With OutMail
.To = "evelyn@xxxxx.com.br"
.CC = ""
.BCC = ""
.Subject = "Novo Registro de Ocorrência no SAC"
.Body = texto
.Display 'Utilize Send para enviar o email sem abrir o Outlook
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
-
Coloque no formulário:
Private Sub CommandbuttonSalva_Click() 'Faça aqui as validações e operações necessários do seu código 'Se alguma coisa der errada, use a instrução Exit Sub para sair do procedimento. EMail_Automátic End Sub Sub EMail_Automátic() '========================================================== 'PARA REMESSA DE E-MAIL AUTOMÁTICO DE DENTRO DAS APLICAÇÕES '========================================================== Dim OutApp As Object Dim OutMail As Object Dim Texto As String Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) Texto = "Há um novo registro de ocorrência no SAC" & vbCrLf & _ "Nº: " & Range("B10").Value & vbCrLf & "Aberto em: " & Range("G5").Value & vbCrLf & _ "Por: " & Range("B5").Value & vbCrLf & _ "Relato: " & Range("B23").Value With OutMail .To = "evelyn@xxxxx.com.br" .CC = "" .BCC = "" .Subject = "Novo Registro de Ocorrência no SAC" .Body = Texto .Display 'Utilize Send para enviar o email sem abrir o Outlook End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub
http://www.ambienteoffice.com.br - http://www.clarian.com.br
-
-
Algo como:
Sub Salvar() Sheets("Planilha de Acompalhamento").Select Sheets("Planilha de Acompalhamento").Name = "Planilha de Acompalhamento" Range("A3").Select Range(Selection, Selection.End(xlToRight)).Select Selection.Copy Range("A4").Select Range(Selection, Selection.End(xlToRight)).Select Range("A4:AE4").Select Range("AE4").Activate Selection.Insert Shift:=xlDown Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("D14").Select Application.CutCopyMode = False Sheets("Planilha de Acompalhamento").Select Rows("3:3").Select Selection.EntireRow.Hidden = True Sheets("Rel_Imprimir").Select EMail_Automátic End Sub Sub EMail_Automátic() '========================================================== 'PARA REMESSA DE E-MAIL AUTOMÁTICO DE DENTRO DAS APLICAÇÕES '========================================================== Dim OutApp As Object Dim OutMail As Object Dim Texto As String Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) Texto = "Há um novo registro de ocorrência no SAC" & vbCrLf & _ "Nº: " & Range("B10").Value & vbCrLf & "Aberto em: " & Range("G5").Value & vbCrLf & _ "Por: " & Range("B5").Value & vbCrLf & _ "Relato: " & Range("B23").Value With OutMail .To = "evelyn@xxxxx.com.br" .CC = "" .BCC = "" .Subject = "Novo Registro de Ocorrência no SAC" .Body = Texto .Display 'Utilize Send para enviar o email sem abrir o Outlook End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub
http://www.ambienteoffice.com.br - http://www.clarian.com.br
- Marcado como Resposta Felipe Costa GualbertoMVP, Moderator segunda-feira, 4 de julho de 2016 13:56
-
-
-
-
-
Olá Felipe, conseguir!
Segue resolução:
Sub Salvar()
RelImprimir.Calculate
Acompanhamento.Calculate
Acompanhamento.Rows("4:4").Insert Shift:=xlDown
Acompanhamento.Range("A4:AE4").Value = Acompanhamento.Range("A3:AE3").Value
MsgBox "Registros salvos com sucesso!" & vbNewLine & "Aperte em OK para sair do aviso", , "Aviso!"
Call EMail_Automático
End Sub
Sub EMail_Automático()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "evelyn@v.com.br"
.CC = ""
.BCC = ""
.Subject = "Novo Registro de Ocorrência no SAC"
.Body = "Há um novo registro de ocorrência no SAC" & vbCrLf & _
"Nº: " & Range("B10").Value & vbCrLf & _
"Aberto em: " & Range("G5").Value & vbCrLf & _
"Por: " & Range("B5").Value & vbCrLf & _
"Relato: " & Range("B23").Value
.Send 'Utilize Send para enviar o email sem abrir o Outlook ou ultilize Display para ve o e-mail antes de enviar
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Muito Obrigada pela paciência e dedicação!
- Marcado como Resposta Felipe Costa GualbertoMVP, Moderator segunda-feira, 4 de julho de 2016 13:56