Responder apenas ao último e-mail no Outlook do Excel VBA

Laucir Miranda

New Member
Joined
Jul 25, 2022
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
  2. Web
Olá,
Consegui adaptar o código acima para uma aplicação que tenho. No entanto, também gostaria de após encontrar o último e-mail enviado copiar intervalo que tenho no excel (A2:F40) no corpo do e-mail e após o envio do e-mail, e-mail em uma pasta específica para fora do Outlook (tenho o nome da pasta e do arquivo em um intervalo no excel (A41:A42). Se Puderem me ajudar com o código...

Meu Script (VBA):

Sub Encaminhar_No_Movements()
'ZVI:2018-11-29 Responder apenas ao último e-mail no Outlook do Excel VBA

' constante do Outlook
Const olFolderSentMail = 5

' Variáveis
Dim OutlookApp como objeto
Dim IsOutlookCriado como booleano
Dim sFilter As String, sSubject As String



' Obtém/cria objeto do Outlook
Em Erro Continuar Próximo
Definir OutlookApp = GetObject(, "Outlook.Application")
Se Errar Então
Set OutlookApp = CreateObject("Outlook.Application")
IsOutlookCreated = Verdadeiro
Fim se
Em erro GoTo 0

'Restringir itens
sAssunto = ActiveCell.Value
sFilter = "[Assunto] = '" & sAssunto & "'"

' Diretor
Com OutlookApp.Session.GetDefaultFolder(olFolderSentMail).Items.Restrict(sFilter)
Se .Contagem > 0 Então .Classificar
"ReceivedTime", Verdadeiro
'Com .Item(1).ResponderTodos
Com .Item(1).Encaminhar
.Para = Planilhas("Planilha3").Range("C10")
'.Destinatários.Adicione " seuemail@email.com.br "

.Exibição
'.Mandar


Terminar com
Senão
MsgBox "Nenhum email encontrado com Assunto:" & vbLf & "'" & sSubject & "'"
Fim se
Terminar com

' Sai da instância do Outlook foi criada por este código
If IsOutlookCreated Then
OutlookApp.Quit
Definir OutlookApp = Nada
Fim se

Finalizar Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,089
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top