Question : Excel VBA read an Outlook folder into Excel

I have the following Excel code which works fine for importing the Subject and Date Stamp of the items in my Inbox.  I want to modify it to import from a sub-folder in my Inbox called "Tickets".  Is there any way to do this?

Sub ListAllItemsInInbox()
    Dim OLF As outlook.MAPIFolder, CurrUser As String
    Dim EmailItemCount As Integer, I As Integer, EmailCount As Integer
    Application.ScreenUpdating = False
    Sheets("Sheet1").Select
    Cells.Clear
    Range("A1").Select
    ' add headings
    Cells(1, 1).Formula = "Subject"
    Cells(1, 2).Formula = "Recieved"
    With Range("A1:B1").Font
        .Bold = True
        .Size = 14
    End With
    Application.Calculation = xlCalculationManual
    Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    EmailItemCount = OLF.Items.Count
    I = 0: EmailCount = 0
    ' read e-mail information
    While I < EmailItemCount
        I = I + 1
        If I Mod 50 = 0 Then Application.StatusBar = "Reading e-mail messages " & Format(I / EmailItemCount, "0%") & "..."
        With OLF.Items(I)
            EmailCount = EmailCount + 1
            Cells(EmailCount + 1, 1).Formula = .Subject
            Cells(EmailCount + 1, 2).Formula = Format(.ReceivedTime, "mm/dd/yyyy hh:mm")
        End With
    Wend
    Application.Calculation = xlCalculationAutomatic
    Set OLF = Nothing
End Sub

Answer : Excel VBA read an Outlook folder into Excel

Hi, malcolm29.

That's simple.  Change this line of code

Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

to

Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Tickets")
Random Solutions  
 
programming4us programming4us