Candido 0 Posted August 29, 2019 Report Share Posted August 29, 2019 Oi pessoal estou com um problema que não consigo resolver. O que eu queria fazer era o seguinte: Sempre que o valor constante linha 16 for igual ao valor da linha 9, a macro executasse automaticamente, ou seja, enviando um e-mail com a informação, segue eu precisasse digitar o valor na linha. Obs.: A linha 9 é uma fórmula, ou seja, não digito o valor. Na linha 16, o valor é digitado e quando o valor da linha 9 (que é fórmula) atingir automaticamente o valor da linha 16, o e-mail é disparado. Segue abaixo a macro que de estou tentando resolver o problema: Private Sub Worksheet_Change(ByVal Target As Range) Dim OutApp As Object Dim OutMail As Object Dim texto As String Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) linha = Target.Row If Target.Address = "$I$" & linha Then If Planilha11.Cells(linha, 16) = Planilha11.Cells(linha, 9) Then With OutMail .To = "xxxxxxxxx@gmail.com" .CC = "" .BCC = "" .Subject = " A Ação " & Planilha11.Cells(linha, 1) & "," & " atingiu o valor " & Planilha11.Cells(linha, 16) .Body = texto .Send 'Utilize Send para enviar o email sem abrir o Outlook End With End If On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End If End Sub Link to post Share on other sites
Afonso Mira 0 Posted September 26, 2019 Report Share Posted September 26, 2019 Crie a seguinte macro: Sub EnviarEmail() Dim OutApp As Object Dim OutMail As Object Dim texto As String Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) linha = Target.Row If Target.Address = "$I$" & linha Then If Planilha11.Cells(linha, 16) = Planilha11.Cells(linha, 9) Then With OutMail .To = "xxxxxxxxx@gmail.com" .CC = "" .BCC = "" .Subject = " A Ação " & Planilha11.Cells(linha, 1) & "," & " atingiu o valor " & Planilha11.Cells(linha, 16) .Body = texto .Send 'Utilize Send para enviar o email sem abrir o Outlook End With End If On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End If End Sub De seguida na folha onde deseja chamar a macro insira o seguinte código: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then Call EnviarEmail End If End Sub Afonso Mira 😃 Estagiando por aqui: Kemet Electronics Portugal, S.A. Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now