kalpeshyogi93
New Member
- Joined
- Sep 17, 2016
- Messages
- 3
Hi Excellers,
I am trying to fetch my email data into excel.
Some how I find the code from net but facing the error like object doesn't support.
I investigate and got to know might be its just because of access of multiple accounts.
Could you please help me with this:
Below is the code
Thank you in advance!
I am trying to fetch my email data into excel.
Some how I find the code from net but facing the error like object doesn't support.
I investigate and got to know might be its just because of access of multiple accounts.
Could you please help me with this:
Below is the code
Code:
Option Explicit
Sub ListOutlookEmailInfoExcel()
Dim oINS As Outlook.Namespace
Dim olTaskFolder As Outlook.MAPIFolder
Dim olTask As Outlook.TaskItem
Dim olItems As Outlook.Items
Dim xlApp As Excel.Application
Dim xlWb As Excel.Workbook
Dim x As Long
Dim arrHeaders As Variant
Set oINS = GetNamespace("MAPI")
Set olTaskFolder = oINS.GetDefaulFolder(olFolderInbox)
Set olItems = olTaskFolder.Items
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWb = xlApp.Workbook.Add
On Error Resume Next
x = 2
arrHeaders = Array("Date Created", "Date received", "Subject", "Sender", "Sender's Email Address", "CC", "BCC", "Sender's Email Type", "Size", "Unread")
xlWb.Worksheets(1).Range("A1").Resize(1, UBound(arrHeaders)).Value = ""
Do
With xlWb.Worksheets(1)
If Not (olItems(x).Subject = "" And olItems(x).Creationtime = "") Then
.Cells(x, 1).Value = olItems(x).Creationtime
.Cells(x, 2).Value = olItems(x).Receivedtime
.Cells(x, 3).Value = olItems(x).Subject
.Cells(x, 4).Value = olItems(x).SenderName
.Cells(x, 5).Value = olItems(x).SenderEmailAddress
.Cells(x, 6).Value = olItems(x).CC
.Cells(x, 7).Value = olItems(x).BCC
.Cells(x, 8).Value = olItems(x).SenderEmailType 'Ex: Internal server; SMTP or SMFP? Internal Server
.Cells(x, 9).Value = Format((olItems(x).Size / 1024) / 1024, "#,##0.00") & "MB"
.Cells(x, 10).Value = olItems(x).Unread
x = x + 1
End If
End With
Loop Until x >= olItems.Count + 1
Set oINS = Nothing
Set olTaskFolder = Nothing
Set olItems = Nothing
Set xlApp = Nothing
Set xlWb = Nothing
End Sub
Thank you in advance!