Copiar conteúdo do Outlook para Excel

Status
Not open for further replies.

RodrigoFinguer

Board Regular
Joined
Jun 13, 2017
Messages
75
Bom dia galera,

Estou com um código VBA para pegar umas informações do outlook mas ele está dando erro da coluna "G" para frente. Não consigo descobrir o que é, podem me ajudar?

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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Status
Not open for further replies.

Forum statistics

Threads
1,213,534
Messages
6,114,184
Members
448,554
Latest member
Gleisner2

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