Results 1 to 1 of 1

Count Emails, No display of date when no mails received, Outlook folders to Excel range

Threaded View

dude6571 Count Emails, No display of... 12-08-2019, 05:30 PM
  1. #1
    Registered User
    Join Date
    01-11-2013
    Location
    London
    MS-Off Ver
    Excel 2013, 2016
    Posts
    95

    Count Emails, No display of date when no mails received, Outlook folders to Excel range

    Hi,

    From code below, I would like to be able to query from a range of chosen date and only showing date with received emails.
    Any help would b highly appreciated.

    Cheers
    dude6571

    
    Sub HowMany_Dated_Emails()
        
        ' Set Variables
        Dim objOutlook As Object, objnSpace As Object, objFolder As Object
        Dim emailCount As Integer, DateCount As Integer, iCount As Integer
        Dim myDate As Date, i As Integer
        Dim arrEmailDates()
        
        ' Get Outlook Object
        Set objOutlook = CreateObject("Outlook.Application")
        Set objnSpace = objOutlook.GetNamespace("MAPI")
        
        ' Get Folder Object
        On Error Resume Next
        
        ' **** Set Folder Folder from Outlook structure ****
        ' **** Mailbox Name => Right-click on Inbox, Properties, Location: \\Mailbox Name
        ' **** Inbox
        ' **** FolderName
        ' **** SubFolderName
        ' **** Set objFolder = objnSpace.Folders("Mailbox").Folders("Inbox").Folders("FolderName").Folders("SubFolderName") ****
        
        ' **** Choose Folders
        Set objFolder = objnSpace.Folders("Mailbox").Folders("Inbox").Folders("FolderName").Folders("SubFolderName")
        
        If Err.Number <> 0 Then
            Err.Clear
            MsgBox "No such folder."
            Set objFolder = Nothing
            Set objnSpace = Nothing
            Set objOutlook = Nothing
            Exit Sub
        End If
        
        ' Put ReceivedTimes in array
        emailCount = objFolder.Items.Count
        For iCount = 1 To emailCount
            With objFolder.Items(iCount)
                ReDim Preserve arrEmailDates(iCount - 1)
                arrEmailDates(iCount - 1) = DateSerial(Year(.ReceivedTime), Month(.ReceivedTime), Day(.ReceivedTime))
            End With
        Next iCount
        
        ' Clear Outlook objects
        Set objFolder = Nothing
        Set objnSpace = Nothing
        Set objOutlook = Nothing
    
        ' Count the emails dates equal to active cell
        Sheets("CountMails").Range("A1").Select
        Do Until IsEmpty(ActiveCell)
            
            DateCount = 0
            myDate = ActiveCell.Value
            
            For i = 0 To UBound(arrEmailDates) - 1
                If arrEmailDates(i) = myDate Then DateCount = DateCount + 1
            Next i
             
            Selection.Offset(0, 1).Activate
            ActiveCell.Value = DateCount
            Selection.Offset(1, -1).Activate
        Loop
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Count Emails in outlook mail box and enter count and oldest email date into excel cell
    By fireguy7 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-24-2018, 11:04 AM
  2. [SOLVED] Count emails in Outlook before set date
    By Stromming in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2016, 06:51 AM
  3. search outlook emails at given date range
    By lubbamkt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2015, 10:41 AM
  4. Set up Outlook rule to move eMails to respective sub folders
    By Karen615 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 04-22-2015, 02:30 PM
  5. [SOLVED] Select folder and date range to get emails from Outlook
    By 2sqrd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2013, 09:51 AM
  6. COPY outlook mails subject, received date, sender details in excel
    By Ratnakar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-27-2012, 10:14 AM
  7. Count of emails by folder and received date
    By TypicalDru in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-16-2012, 04:48 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1