VBA - Count Emails Multiple Inboxes

t0ny84

Board Regular
Joined
Jul 6, 2020
Messages
205
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
  2. Mobile
  3. Web
Hi,

I am hoping someone can assist with modifying the below two scripts to allow me to:
- Export a list of Non-Completed Email counts for 5 inboxes to a table in Excel (Example layout below).
- Be modular so I can add or remove emails as required.
- If an email address isn't accessible the script skips checking that email and moves on to the next email.
- Have the option to access sub folders if needed.

Table Example
COLUMN A | COLUMN B
Email Address | Total Non-Completed Emails
Inbox@Email1.com - 15
Inbox2@Email2.com - 12

VBA Code:
Sub HowManyEmails()
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("MAILBOX_1").Folders("Inbox")
   If Err.Number <> 0 Then
   Err.Clear
   MsgBox "No such folder."
   Exit Sub
   End If
   
   EmailCount = objFolder.Items.Count
   Set objFolder = Nothing
   Set objnSpace = Nothing
   Set objOutlook = Nothing

MsgBox "Number of emails in the folder: " & EmailCount, , "MIS email count"
End Sub

VBA Code:
Sub EmailCount()
' Requires Microsoft Outlook 15 Object Library

Dim Folder As Outlook.MAPIFolder


Dim objOL As Outlook.Application
Set objOL = New Outlook.Application


MailBoxName = "MAILBOX_NUMBER_ 1"
Main_Folder_Name = "Inbox"
Sub_Folder_Name = "SUB FOLDER"


'Set Folder = Outlook.Session.Folders(MailBoxName).Folders(Main_Folder_Name) '.Folders(Sub_Folder_Name)


Dim itms As Outlook.Items
Set itms = Folder.Items


Dim FollowupItms As Outlook.Items
Set FollowupItms = itms.Restrict("[FlagStatus] = 0")

Followup = FollowupItms.Count
Worksheets("Sheet1").Range("A1").Value = Followup
End Sub

Thanks in advance
t0ny84
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

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