Forum Discussion

JoshuaHughes1's avatar
JoshuaHughes1
Copper Contributor
Dec 12, 2024

Excel pulls data from Outlook

Hello,

 

We currently have an excel sheet which we access input the previous days date, todays date and hit a button and it shows all the incoming mail into a teams outlook mailbox.

This is an old excel sheet we have been using for many years and now i need to do it for newer teams and am unable to work out how this is possible.

I've looked online and used co-pilot and unable to find the answers.

Attached screenshots below, i thought just changing the hyperlink would work but i think it's more in depth that than.

 

Any help appreciated

 

Joshua 

2 Replies

  • Please refer on below:

     

    Sub GetEmails()
        Dim OutlookApp As Object
        Dim OutlookNamespace As Object
        Dim Folder As Object
        Dim Item As Object
        Dim i As Integer
        
        Set OutlookApp = CreateObject("Outlook.Application")
        Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
        Set Folder = OutlookNamespace.Folders("YourMailboxName").Folders("Inbox")
        
        For i = Folder.Items.Count To 1 Step -1
            Set Item = Folder.Items(i)
            If Item.ReceivedTime >= Range("StartDate").Value And Item.ReceivedTime <= Range("EndDate").Value Then
                ' Process the email
            End If
        Next i

     

Resources