t0ny84
Board Regular
- Joined
- Jul 6, 2020
- Messages
- 205
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
- Mobile
- 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
Thanks in advance
t0ny84
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