Outlook to excel automation

Shantanu_4612

New Member
Joined
Oct 3, 2016
Messages
27
Hi all,

I have found the below mentioned code for outlook 15.0
Can someone help me to make changes in the code for outlook 10.0 which can be used in a button in excel user form to extract data in "extract raw" sheet
this code is giving me "2147221233 (8004010f)" error

Below is the code
Code:
' Requires Tools-->References-->Microsoft Outlook 15.0 Object Library
Sub getEmails()

    Dim olApp As Outlook.Application
    Dim olNS As Outlook.Namespace
    Dim olFldr As Outlook.MAPIFolder
    Dim olItem As Object
    Dim olMailItem As Outlook.MailItem
    Dim ws As Worksheet
    Dim iRow As Long
    Dim hdr As Variant
    
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    
    Set olApp = New Outlook.Application
    Set olNS = olApp.GetNamespace("MAPI")
    
    Set olFldr = olNS.Folders(1)
    Set olFldr = olFldr.Folders("Inbox")
    Set olFldr = olFldr.Folders("MrExcel")
    Set olFldr = olFldr.Folders("Keep")
    
    ws.Cells.Clear
    iRow = 2
    
    Application.ScreenUpdating = False
    For Each olItem In olFldr.Items
        If olItem.Class = olMail Then
            Set olMailItem = olItem
            With olMailItem
                ws.Cells(iRow, "A") = .Sender
                ws.Cells(iRow, "B") = .SenderEmailAddress
                ws.Cells(iRow, "C") = .SenderName
                ws.Cells(iRow, "D") = .Subject
                ws.Cells(iRow, "E") = .ReceivedTime
                ws.Cells(iRow, "F") = .Categories
                ws.Cells(iRow, "G") = .TaskCompletedDate
                ws.Cells(iRow, "H") = olFldr.Name
                iRow = iRow + 1
            End With
        End If
    Next olItem

    With ws
        hdr = Array("Sender", "SenderEmailAddress", "SenderName", "Subject", "ReceicedTime", "Categories", "TaskCompletedDate", "Folder")
        .Range("A1").Resize(, UBound(hdr)) = hdr
        .Columns.AutoFit
    End With
    Application.ScreenUpdating = False
End Sub
 
Last edited by a moderator:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Two questions.

1. Have you set the reference to use Outlook 10.0 (Use the Tools Menu and References and search down for Microsoft Outlook 10.0 Object Library and select teh check box.
2. Have you stepped through the code to see where it is giving you the problem.

On a quick look what if you change this line.

ws.Cells(iRow, "H") = olFldr.Name

To

ws.Cells(iRow, "H") = .olFldr.Name
 
Upvote 0
Hi healey,

I tried doing the recommended changes, but it isn't working.

Still same error.

And I am sorry, I am looking for a macron for outlook 12.0 and not 10.0
 
Upvote 0
Which line causes the error?
 
Upvote 0
Hi,

Thank you for your reply
But I am not sure which line is causing the error as I am getting it as soon as I am running it.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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