How to copy current email texts in Outlook to cells in Excel using VBA?

Asked

Viewed 37 times

1

Good afternoon to you all. I want to create a macro in Excel that copies specific data from a selected email in Outlook, pasting them into respective columns of a spreadsheet, creating a database. Noting that I need to copy from a single email that is selected so that I can work on it individually, I don’t want to go through all the ones in the folder at once.

The images below serve as an example for the operation of the macro. The corresponding e-mail data that is selected are recorded in their respective columns. It follows a code that I worked below, but I didn’t go very far, since I don’t know how to define the object of the currently selected email, but I left some comments that guide the whole procedure. This macro would break me a huge branch, can help me?

Exemplo de um E-mail atual com as informações visadas

inserir a descrição da imagem aqui

A planilha é gradualmente preenchida com os dados correspondentes dos e-mails

Sub dados_eMail()

Dim outApp As Outlook.Application
Dim outMapi As Outlook.MAPIFolder
Dim outMail As Outlook.MailItem
Dim outHTML As MSHTML.HTMLDocument

Dim WB As Workbook
Dim WS As Worksheet
Dim Mail As String
Dim inbox As String
Dim lastrow As Long

Set WB = Workbooks("Book1")
Set WS = Sheets("Sheet1")
WB.Activate
WS.Activate
lastrow = WS.Range("D" & Rows.Count).End(xlUp).Row

Mail = "[email protected]"
inbox = "Inbox"

Set outMapi = outApp.GetNamespace("MAPI").Folders(pasta).Folders(subpasta)
Set outHTML = New MSHTML.HTMLDocument

'1) outMail recebe o objeto que representa o e-mail atualmente selecionado no Outlook;
'2) As palavras que representam os títulos dos cabeçalhos são procurados no e-mail, e os textos abaixo delas são copiados para a primeira célula vazia de cada coluna;
'3) Com todas as células de uma linha preenchidas, a macro é encerrada. 

 End Sub
No answers

Browser other questions tagged

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