Copy outlook e-mail to Excel

RodrigoFinguer

Board Regular
Joined
Jun 13, 2017
Messages
75
I have this VBA code to get some informations from outlook to excel, but my code is getting na error from "G" column to the end and i don't know why, can anyone help me?

Sub Emails_Outlook()
'Carregar e-mails do outlook para o excel
Dim appOutlook As Object
Dim olNS As Object
Dim olFolder As Object
Dim olItem As Object
Dim r As Long
On Error Resume Next
Set appOutlook = GetObject(, "Outlook.Application")
If appOutlook Is Nothing Then
Set appOutlook = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set olNS = appOutlook.GetNamespace("MAPI")
'Abaixo preencha o nome do arquivo de dados PST e a pasta.
'Neste caso o arquivo é Douglas Godoy e a pasta Caixa de Entrada.
Set olFolder = olNS.Folders("rodrigo.finguer@brf-br.com").Folders("Fornecedores")
' Set olRecip = olNS.CreateRecipient("contatofornecedor@brf-br.com")
' Set olFolder = olNS.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("Rodrigo")
Cells.Delete
r = 3
'Cria um array montando o título das colunas no arquivo.
Range("A3:K3") = Array("Título", "Quem enviou", "Para", "Data e Hora", "Anexos", "Tamanho", "Última modificação", "Categoria", "Nome do Remetente", "Tipo de acompanhamento", "Conteúdo")
For Each olItem In olFolder.Items
If TypeName(olItem) = "MailItem" Then
r = r + 1
Cells(r, "A") = olItem.Subject 'Assunto do e-mail
Cells(r, "B") = olItem.SenderEmailAddress 'E-mail do remetente
Cells(r, "C") = olItem.To 'E-mail do destinatário
Cells(r, "D") = olItem.ReceivedTime 'Data/Hora de recebimento
Cells(r, "E") = olItem.Attachments.Count 'Número de anexos
Cells(r, "F") = olItem.Size 'Tamanho da mensagem em bytes
Cells(r, "G") = olMail.LastModificationTime 'Última modificação
Cells(r, "H") = olMail.Categories 'Categoria
Cells(r, "I") = olMail.SenderName 'Nome do remetente
Cells(r, "J") = olMail.FlagRequest 'Acompanhamento
Cells(r, "K") = olItem.Body 'Tome cuidado ao utilizar pois carrega os dados do corpo do email
Application.StatusBar = r
End If
Next olItem
Columns.AutoFit
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
What code line throws the first error? What is the error number and description?
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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