Consulting

Results 1 to 3 of 3

Thread: Retrieving outlook mail items

  1. #1

    Retrieving outlook mail items

    Hi,

    I made a macro used in Excel to retrieve the email date and email sender of a shared outlook mailbox.

    The program is able to retrieve all the emails within a specific month however I am getting a run time error 438 (Object doesnt support this property or method) at the end of the code even though I see it has retrieved all the email.

    The error is situated at If OutlookMail.ReceivedTime >= Range("Start_of_Month").Value Then

    Here is my code. Why am I getting a run time error?

    Thank you!



    Sub getDataFromOutlook()


    Dim OutlookApp As Outlook.Application
    Dim OutlookNamespace As Namespace
    Dim Folder As MAPIFolder
    Dim OutlookMail As Variant
    Dim i As Integer


    Dim strMailboxName As String


    strMailboxName = "client support"




    strMailboxName1 = "Inbox"






    Set OutlookApp = New Outlook.Application


    Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")


    Set Folder = OutlookNamespace.Folders(strMailboxName)


    Set Folder = Folder.Folders(strMailboxName1)


    Set Folder = Folder.Folders("CHRISTINA")






    i = 1




    For Each OutlookMail In Folder.Items






    If OutlookMail.ReceivedTime >= Range("Start_of_Month").Value Then

    If OutlookMail.ReceivedTime <= Range("End_of_Month").Value Then


    Range("Email_Sender").Offset(i, 0) = OutlookMail.SenderName
    Range("Email_Sender").Offset(i, 0).Columns.AutoFit
    Range("Email_Sender").Offset(i, 0).VerticalAlignment = xlTop

    Range("Email_Date").Offset(i, 0) = OutlookMail.SentOn
    Range("Email_Date").Offset(i, 0).Columns.AutoFit
    Range("Email_Date").Offset(i, 0).VerticalAlignment = xlTop


    i = i + 1


    End If

    End If


    Next OutlookMail




    Set Folder = Nothing
    Set OutlookNamespace = Nothing
    Set OutlookApp = Nothing





    End Sub

  2. #2
    Assuming that the start_of_month and end_of_month contain dates then

        For Each OutlookMail In Folder.Items
            If TypeName(OutlookMail) = "MailItem" Then
                If CDate(OutlookMail.ReceivedTime) >= Range("Start_of_Month").value Then
                    If CDate(OutlookMail.ReceivedTime) <= Range("End_of_Month").value Then
    should work.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Hi gmayor,

    thank you so much it works!

    I never would have figured out that the received time had to be converted into data type date.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •