title: VBA count emails module!
body: <p>This is a follow-up question of one which I posted yesterday. I feel I am getting quite close to creating a module in VBA that will count the number of e-mails sent on a particular day of the week. For the moment the day chosen is Monday. </p>
  
  <p>However, the code is not yet working, and Outlook refuses to see the particular module.<br>
  I am sure there are a couple of errors in it. If someone could point these out, I would greatly appreciate it.<br>
  I also think that such code could be useful for others for future reference as the code for this kind of module does not seem to be readily available on the internet (I've looked!) and yet forms a type of search parameter that many will find useful!</p>
  
  <pre><code>Sub Count2(Optional dteDate As Date)
    Dim objOutlook As Object, objnSpace As Object, objFolder As Object
    Dim EmailCount As Integer    
    Set objOutlook = CreateObject("Outlook.Application")
    Set objnSpace = objOutlook.GetNamespace("MAPI")
  
    On Error Resume Next
  
    Set objFolder = objnSpace.Folders("My Personal Emails").Folders("spam")
    If Err.Number &lt;&gt; 0 Then 
      Err.Clear
      MsgBox "No such folder."
      Exit Sub
    End If
  
    Select Case Weekday(dteDate)
      Case vbMonday
        dteDate = Date
      End Select
  
    For Each MapiItem In MapiFolderInbox.Messages
      If MapiItem.TimeReceived = Date Then
        Count = Count + 1
        Next MapiItem   
      End If
  
    EmailCount = objFolder.Items.Count
    Set objFolder = Nothing
    Set objnSpace = Nothing
    Set objOutlook = Nothing
  
    MsgBox "Number of emails in the folder: " _
      &amp; EmailCount, , "Number of spam messages sent on a Monday: " &amp; Count        
  End Sub
  </code></pre>