How to Extract Data from Attachments in Outlook

Photomofo

Active Member
Joined
Aug 20, 2012
Messages
259
Good Morning,

I'm trying to write a sub that downloads attachments from Outlook. I'm building off the code I found here. My only real problem is that this code is pointed at my Primary inbox and I need to be able to customize which folder to target.


I found this tool here that does exactly what I want but he's got it password protected. In his spreadsheet he's got a box marked Retrieve From and it's got a dropdown so you can select which specific folder to get attachments from. I don't need a drop down but I need some way to control which Folder is targeted.

Can someone point me in the right direction? I've never done any interfacing with Outlook so I'm not familiar with how to do this.

 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Is it a sub folder of inbox? I played around and got the below working if that's helpful.

VBA Code:
Public Sub OutlookFolderTest()

    Dim OlApp As New Outlook.Application
    Dim OlFolder As Outlook.MAPIFolder
    Dim OlSubFolder As Outlook.MAPIFolder
        
    Set OlApp = GetObject(, "Outlook.Application")
    
    If Err.Number = 429 Then
        Set OlApp = CreateObject("Outlook.application")
    End If
    
    ' Inbox
    Set OlFolder = OlApp.Session.GetDefaultFolder(olFolderInbox)

    ' Example of getting a specific sub folder
    Set OlSubFolder = OlFolder.Folders.Item("NameOfFolder")
    MsgBox OlSubFolder.Name & " : " & OlSubFolder.Items.Count
    
    ' Example of getting all sub folders
    If (OlFolder.Folders.Count > 0) Then
        For Each OlFolder In OlFolder.Folders
            MsgBox OlFolder.Name & " : " & OlFolder.Items.Count
        Next
    End If


'clean up
Set OlFolder = Nothing
Set OlSubFolder = Nothing
Set OlApp = Nothing

End Sub
 
Upvote 0
Nice name QR. Thank you for your time and effort. I only come here after hitting a brick wall after a couple of hours of trying. I solved the problem using a very similar approach to what you've listed here.

We've got multiple inboxes depending on job qualification. The inbox I was trying to identify wasn't my personal account but a shared account so I had to figure out a way to move though the folders until I found the right Sub Folder to interrogate.
 
Upvote 0

Forum statistics

Threads
1,215,779
Messages
6,126,853
Members
449,345
Latest member
CharlieDP

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